Return-Path: X-Original-To: apmail-eagle-commits-archive@minotaur.apache.org Delivered-To: apmail-eagle-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4645F18D75 for ; Fri, 26 Feb 2016 21:26:36 +0000 (UTC) Received: (qmail 33866 invoked by uid 500); 26 Feb 2016 21:26:36 -0000 Delivered-To: apmail-eagle-commits-archive@eagle.apache.org Received: (qmail 33837 invoked by uid 500); 26 Feb 2016 21:26:36 -0000 Mailing-List: contact commits-help@eagle.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@eagle.incubator.apache.org Delivered-To: mailing list commits@eagle.incubator.apache.org Received: (qmail 33828 invoked by uid 99); 26 Feb 2016 21:26:36 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Feb 2016 21:26:36 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 9BFCBC093B for ; Fri, 26 Feb 2016 21:26:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.549 X-Spam-Level: X-Spam-Status: No, score=-3.549 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.329] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id v66zyllKLkpC for ; Fri, 26 Feb 2016 21:26:23 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 7DEBA5FBB2 for ; Fri, 26 Feb 2016 21:26:20 +0000 (UTC) Received: (qmail 32439 invoked by uid 99); 26 Feb 2016 21:26:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Feb 2016 21:26:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 704CCE03C2; Fri, 26 Feb 2016 21:26:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hdendukuri@apache.org To: commits@eagle.incubator.apache.org Date: Fri, 26 Feb 2016 21:26:23 -0000 Message-Id: <49ae0cbd8614464389ce8ec4037dd5c8@git.apache.org> In-Reply-To: <3e00d7d5028547c283bfe80fcc09cd2e@git.apache.org> References: <3e00d7d5028547c283bfe80fcc09cd2e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/9] incubator-eagle git commit: EAGLE-139 EAGLE-163 Eagle UI Modularization and fix bugs in policy extensions http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js b/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js new file mode 100644 index 0000000..50f377c --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/common/controller.js @@ -0,0 +1,1023 @@ +/* + * 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 featureControllers = angular.module("featureControllers"); + var feature = featureControllers.register("common"); + + // ============================================================== + // = Function = + // ============================================================== + feature.service("Policy", function(Entities) { + var Policy = function () {}; + + Policy.updatePolicyStatus = function(policy, status) { + $.dialog({ + title: "Confirm", + content: "Do you want to " + (status ? "enable" : "disable") + " policy[" + policy.tags.policyId + "]?", + confirm: true + }, function(ret) { + if(ret) { + policy.enabled = status; + Entities.updateEntity("AlertDefinitionService", policy); + } + }); + }; + Policy.deletePolicy = function(policy, callback) { + $.dialog({ + title: "Confirm", + content: "Do you want to delete policy[" + policy.tags.policyId + "]?", + confirm: true + }, function(ret) { + if(ret) { + policy.enabled = status; + Entities.deleteEntity("AlertDefinitionService", policy)._promise.finally(function() { + if(callback) { + callback(policy); + } + }); + } + }); + }; + return Policy; + }); + + // ============================================================== + // = Policies = + // ============================================================== + + // ========================= Policy List ======================== + feature.navItem("policyList", "Policies", "list"); + feature.controller('policyList', function(PageConfig, Site, $scope, Application, Entities, Policy) { + PageConfig.pageTitle = "Policy List"; + PageConfig.pageSubTitle = Site.current().tags.site; + + // Initial load + $scope.policyList = []; + $scope.application = Application.current(); + + // List policies + var _policyList = Entities.queryEntities("AlertDefinitionService", {site: Site.current().tags.site, dataSource: $scope.application.tags.application}); + _policyList._promise.then(function() { + $.each(_policyList, function(i, policy) { + policy.__mailStr = common.getValueByPath(common.parseJSON(policy.notificationDef, {}), "0.recipients", ""); + policy.__mailList = policy.__mailStr.trim() === "" ? [] : policy.__mailStr.split(/[,;]/); + policy.__expression = common.parseJSON(policy.policyDef, {}).expression; + + $scope.policyList.push(policy); + }); + }); + $scope.policyList._promise = _policyList._promise; + + // Function + $scope.searchFunc = function(item) { + var key = $scope.search; + if(!key) return true; + + var _key = key.toLowerCase(); + function _hasKey(item, path) { + var _value = common.getValueByPath(item, path, "").toLowerCase(); + return _value.indexOf(_key) !== -1; + } + return _hasKey(item, "tags.policyId") || _hasKey(item, "__expression") || _hasKey(item, "desc") || _hasKey(item, "owner") || _hasKey(item, "__mailStr"); + }; + + $scope.updatePolicyStatus = Policy.updatePolicyStatus; + $scope.deletePolicy = function(policy) { + Policy.deletePolicy(policy, function(policy) { + var _index = $scope.policyList.indexOf(policy); + $scope.policyList.splice(_index, 1); + }); + }; + }); + + // ======================= Policy Detail ======================== + feature.controller('policyDetail', function(PageConfig, Site, $scope, $wrapState, Entities, Policy, nvd3) { + var MAX_PAGESIZE = 10000; + + PageConfig.pageTitle = "Policy Detail"; + PageConfig.lockSite = true; + PageConfig + .addNavPath("Policy List", "/common/policyList") + .addNavPath("Policy Detail"); + + $scope.chartConfig = { + chart: "line", + xType: "time" + }; + + // Query policy + if($wrapState.param.filter) { + $scope.policyList = Entities.queryEntity("AlertDefinitionService", $wrapState.param.filter); + } else { + $scope.policyList = Entities.queryEntities("AlertDefinitionService", { + policyId: $wrapState.param.policy, + site: $wrapState.param.site, + alertExecutorId: $wrapState.param.executor + }); + } + + $scope.policyList._promise.then(function() { + var policy = null; + + if($scope.policyList.length === 0) { + $.dialog({ + title: "OPS!", + content: "Policy not found!" + }, function() { + location.href = "#/common/policyList"; + }); + return; + } else { + policy = $scope.policyList[0]; + + policy.__mailStr = common.getValueByPath(common.parseJSON(policy.notificationDef, {}), "0.recipients", ""); + policy.__mailList = policy.__mailStr.trim() === "" ? [] : policy.__mailStr.split(/[,;]/); + policy.__expression = common.parseJSON(policy.policyDef, {}).expression; + + $scope.policy = policy; + Site.current(Site.find($scope.policy.tags.site)); + console.log($scope.policy); + } + + // Visualization + var _endTime = app.time.now().hour(23).minute(59).second(59).millisecond(0); + var _startTime = _endTime.clone().subtract(1, "month").hour(0).minute(0).second(0).millisecond(0); + var _cond = { + dataSource: policy.tags.dataSource, + policyId: policy.tags.policyId, + _startTime: _startTime, + _endTime: _endTime + }; + + // > eagle.policy.eval.count + $scope.policyEvalSeries = nvd3.convert.eagle([Entities.querySeries("GenericMetricService", $.extend({_metricName: "eagle.policy.eval.count"}, _cond), "@cluster", "sum(value)", 60 * 24)]); + + // > eagle.policy.eval.fail.count + $scope.policyEvalFailSeries = nvd3.convert.eagle([Entities.querySeries("GenericMetricService", $.extend({_metricName: "eagle.policy.eval.fail.count"}, _cond), "@cluster", "sum(value)", 60 * 24)]); + + // > eagle.alert.count + $scope.alertSeries = nvd3.convert.eagle([Entities.querySeries("GenericMetricService", $.extend({_metricName: "eagle.alert.count"}, _cond), "@cluster", "sum(value)", 60 * 24)]); + + // > eagle.alert.fail.count + $scope.alertFailSeries = nvd3.convert.eagle([Entities.querySeries("GenericMetricService", $.extend({_metricName: "eagle.alert.fail.count"}, _cond), "@cluster", "sum(value)", 60 * 24)]); + + // Alert list + $scope.alertList = Entities.queryEntities("AlertService", { + site: Site.current().tags.site, + dataSource: policy.tags.dataSource, + policyId: policy.tags.policyId, + _pageSize: MAX_PAGESIZE, + _duration: 1000 * 60 * 60 * 24 * 30, + __ETD: 1000 * 60 * 60 * 24 + }); + }); + + // Function + $scope.updatePolicyStatus = Policy.updatePolicyStatus; + $scope.deletePolicy = function(policy) { + Policy.deletePolicy(policy, function() { + location.href = "#/common/policyList"; + }); + }; + }); + + // ======================== Policy Edit ========================= + function policyCtrl(create, PageConfig, Site, Policy, $scope, $wrapState, $q, Entities, Application, Authorization) { + PageConfig.pageTitle = create ? "Policy Create" : "Policy Edit"; + PageConfig.pageSubTitle = Site.current().tags.site; + PageConfig + .addNavPath("Policy List", "/common/policyList") + .addNavPath("Policy Edit"); + + var _winTimeDesc = "Number unit[millisecond, sec, min, hour, day, month, year]. e.g. 23 sec"; + var _winTimeRegex = /^\d+\s+(millisecond|milliseconds|second|seconds|sec|minute|minutes|min|hour|hours|day|days|week|weeks|month|months|year|years)$/; + var _winTimeDefaultValue = '10 min'; + $scope.config = { + window: [ + // Display name, window type, required columns[Title, Description || "LONG_FIELD", Regex check, default value] + { + title: "Message Time Slide", + description: "Using timestamp filed from input is used as event's timestamp", + type: "externalTime", + fields:[ + {title: "Field", defaultValue: "timestamp", hide: true}, + {title: "Time", description: _winTimeDesc, regex: _winTimeRegex, defaultValue: _winTimeDefaultValue} + ] + }, + { + title: "System Time Slide", + description: "Using System time is used as timestamp for event's timestamp", + type: "time", + fields:[ + {title: "Time", description: _winTimeDesc, regex: _winTimeRegex, defaultValue: _winTimeDefaultValue} + ] + }, + { + title: "System Time Batch", + description: "Same as System Time Window except the policy is evaluated at fixed duration", + type: "timeBatch", + fields:[ + {title: "Time", description: _winTimeDesc, regex: _winTimeRegex, defaultValue: _winTimeDefaultValue} + ] + }, + { + title: "Length Slide", + description: "The slide window has a fixed length", + type: "length", + fields:[ + {title: "Number", description: "Number only. e.g. 1023", regex: /^\d+$/} + ] + }, + { + title: "Length Batch", + description: "Same as Length window except the policy is evaluated in batch mode when fixed event count reached", + type: "lengthBatch", + fields:[ + {title: "Number", description: "Number only. e.g. 1023", regex: /^\d+$/} + ] + } + ] + }; + + $scope.create = create; + $scope.encodedRowkey = $wrapState.param.filter; + + $scope.step = 0; + $scope.dataSources = {}; + $scope.policy = {}; + + // ========================================== + // = Data Preparation = + // ========================================== + // Steam list + var _streamList = Entities.queryEntities("AlertStreamService", {dataSource: Application.current().tags.application}); + var _executorList = Entities.queryEntities("AlertExecutorService", {dataSource: Application.current().tags.application}); + $scope.streamList = _streamList; + $scope.executorList = _executorList; + $scope.streamReady = false; + + $q.all([_streamList._promise, _executorList._promise]).then(function() { + // Map executor with stream + $.each(_executorList, function(i, executor) { + $.each(_streamList, function(j, stream) { + if(stream.tags.dataSource === executor.tags.dataSource && stream.tags.streamName === executor.tags.streamName) { + stream.alertExecutor = executor; + return false; + } + }); + }); + + // Fill stream list + $.each(_streamList, function(i, unit) { + var _srcStreamList = $scope.dataSources[unit.tags.dataSource] = $scope.dataSources[unit.tags.dataSource] || []; + _srcStreamList.push(unit); + }); + + $scope.streamReady = true; + + // ========================================== + // = Function = + // ========================================== + function _findStream(dataSource, streamName) { + var _streamList = $scope.dataSources[dataSource]; + if(!_streamList) return null; + + for(var i = 0 ; i < _streamList.length ; i += 1) { + if(_streamList[i].tags.streamName === streamName) { + return _streamList[i]; + } + } + return null; + } + + // ========================================== + // = Step control = + // ========================================== + $scope.steps = [ + // >> Select stream + { + title: "Select Stream", + ready: function() { + return $scope.streamReady; + }, + init: function() { + $scope.policy.__.streamName = $scope.policy.__.streamName || + common.array.find($scope.policy.tags.dataSource, _streamList, "tags.dataSource").tags.streamName; + }, + nextable: function() { + var _streamName = common.getValueByPath($scope.policy, "__.streamName"); + if(!_streamName) return false; + + // Detect stream in current data source list + return !!common.array.find(_streamName, $scope.dataSources[$scope.policy.tags.dataSource], "tags.streamName"); + } + }, + + // >> Define Alert Policy + { + title: "Define Alert Policy", + init: function() { + // Normal mode will fetch meta list + if(!$scope.policy.__.advanced) { + var _stream = _findStream($scope.policy.tags.dataSource, $scope.policy.__.streamName); + $scope._stream = _stream; + + if(!_stream.metas) { + _stream.metas = Entities.queryEntities("AlertStreamSchemaService", {dataSource: $scope.policy.tags.dataSource, streamName: $scope.policy.__.streamName}); + _stream.metas._promise.then(function() { + _stream.metas.sort(function(a, b) { + if(a.tags.attrName < b.tags.attrName) { + return -1; + } else if(a.tags.attrName > b.tags.attrName) { + return 1; + } + return 0; + }); + }); + } + } + }, + ready: function() { + if(!$scope.policy.__.advanced) { + return $scope._stream.metas._promise.$$state.status === 1; + } + return true; + }, + nextable: function() { + if($scope.policy.__.advanced) { + // Check stream source + $scope._stream = null; + $.each($scope.dataSources[$scope.policy.tags.dataSource], function(i, stream) { + if(($scope.policy.__._expression || "").indexOf(stream.tags.streamName) !== -1) { + $scope._stream = stream; + return false; + } + }); + return $scope._stream; + } else { + // Window + if($scope.policy.__.windowConfig) { + var _winMatch = true; + var _winConds = $scope.getWindow().fields; + $.each(_winConds, function(i, cond) { + if(!(cond.val || "").match(cond.regex)) { + _winMatch = false; + return false; + } + }); + if(!_winMatch) return false; + + // Aggregation + if($scope.policy.__.groupAgg) { + if(!$scope.policy.__.groupAggPath || + !$scope.policy.__.groupCondOp || + !$scope.policy.__.groupCondVal) { + return false; + } + } + } + } + return true; + } + }, + + // >> Configuration & Notification + { + title: "Configuration & Notification", + nextable: function() { + return !!$scope.policy.tags.policyId; + } + } + ]; + + // ========================================== + // = Policy Logic = + // ========================================== + _streamList._promise.then(function() { + // Initial policy entity + if(create) { + $scope.policy = { + __: { + toJSON: jQuery.noop, + conditions: {}, + notification: [], + dedupe: { + alertDedupIntervalMin: 10, + emailDedupIntervalMin: 10 + }, + policy: {}, + window: "externalTime", + group: "", + groupAgg: "count", + groupAggPath: "timestamp", + groupCondOp: ">=", + groupCondVal: "2" + }, + desc: "", + enabled: true, + prefix: "alertdef", + remediationDef: "", + tags: { + dataSource: Application.current().tags.application, + policyType: "siddhiCEPEngine" + } + }; + + // If configured data source + if($wrapState.param.dataSrc) { + $scope.policy.tags.dataSource = $wrapState.param.dataSrc; + if(common.array.find($wrapState.param.dataSrc, Site.current().dataSrcList, "tags.dataSource")) { + setTimeout(function() { + $scope.changeStep(0, 2, false); + $scope.$apply(); + }, 1); + } + } + + // Start step + $scope.changeStep(0, 1, false); + console.log($scope.policy); + } else { + var _policy = Entities.queryEntity("AlertDefinitionService", $scope.encodedRowkey); + _policy._promise.then(function() { + if(_policy.length) { + $scope.policy = _policy[0]; + $scope.policy.__ = { + toJSON: jQuery.noop + }; + + Site.current(Site.find($scope.policy.tags.site)); + } else { + $.dialog({ + title: "OPS", + content: "Policy not found!" + }, function() { + $location.path("/common/policyList"); + $scope.$apply(); + }); + return; + } + + // === Revert inner data === + // >> De-dupe + $scope.policy.__.dedupe = common.parseJSON($scope.policy.dedupeDef, {}); + + // >> Notification + $scope.policy.__.notification = common.parseJSON($scope.policy.notificationDef, []); + + // >> Policy + var _policyUnit = $scope.policy.__.policy = common.parseJSON($scope.policy.policyDef); + + // >> Parse expression + $scope.policy.__.conditions = {}; + var _condition = _policyUnit.expression.match(/from\s+(\w+)(\[(.*)])?(#window[^\)]*\))?\s+(select (\w+, )?(\w+)\((\w+)\) as [\w\d_]+ (group by (\w+) )?having ([\w\d_]+) ([<>=]+) ([^\s]+))?/); + var _cond_stream = _condition[1]; + var _cond_query = _condition[3] || ""; + var _cond_window = _condition[4]; + var _cond_group = _condition[5]; + var _cond_groupUnit = _condition.slice(7,14); + + if(!_condition) { + $scope.policy.__.advanced = true; + } else { + // > StreamName + var _streamName = _cond_stream; + var _cond = _cond_query; + + $scope.policy.__.streamName = _streamName; + + // > Conditions + // Loop condition groups + if(_cond.trim() !== "" && /^\(.*\)$/.test(_cond)) { + var _condGrps = _cond.substring(1, _cond.length - 1).split(/\)\s+and\s+\(/); + $.each(_condGrps, function(i, line) { + // Loop condition cells + var _condCells = line.split(/\s+or\s+/); + $.each(_condCells, function(i, cell) { + var _opMatch = cell.match(/(\S*)\s*(==|!=|>|<|>=|<=|contains)\s*('(?:[^'\\]|\\.)*'|[\w\d]+)/); + if(!common.isEmpty(_opMatch)) { + var _key = _opMatch[1]; + var _op = _opMatch[2]; + var _val = _opMatch[3]; + var _conds = $scope.policy.__.conditions[_key] = $scope.policy.__.conditions[_key] || []; + var _type = ""; + if(_val.match(/'.*'/)) { + _val = _val.slice(1, -1); + _type = "string"; + } else if(_val === "true" || _val === "false") { + var _regexMatch = _key.match(/^str:regexp\((\w+),'(.*)'\)/); + var _containsMatch = _key.match(/^str:contains\((\w+),'(.*)'\)/); + var _mathes = _regexMatch || _containsMatch; + if(_mathes) { + _key = _mathes[1]; + _val = _mathes[2]; + _type = "string"; + _op = _regexMatch ? "regex" : "contains"; + _conds = $scope.policy.__.conditions[_key] = $scope.policy.__.conditions[_key] || []; + } else { + _type = "bool"; + } + } else { + _type = "number"; + } + _conds.push($scope._CondUnit(_key, _op, _val, _type)); + } + }); + }); + } else if(_cond_query !== "") { + $scope.policy.__.advanced = true; + } + } + + if($scope.policy.__.advanced) { + $scope.policy.__._expression = _policyUnit.expression; + } else { + // > window + if(!_cond_window) { + $scope.policy.__.window = "externalTime"; + $scope.policy.__.group = ""; + $scope.policy.__.groupAgg = "count"; + $scope.policy.__.groupAggPath = "timestamp"; + $scope.policy.__.groupCondOp = ">="; + $scope.policy.__.groupCondVal = "2"; + } else { + try { + $scope.policy.__.windowConfig = true; + + var _winCells = _cond_window.match(/\.(\w+)\((.*)\)/); + $scope.policy.__.window = _winCells[1]; + var _winConds = $scope.getWindow().fields; + $.each(_winCells[2].split(","), function(i, val) { + _winConds[i].val = val; + }); + + // Group + if(_cond_group) { + $scope.policy.__.group = _cond_groupUnit[3]; + $scope.policy.__.groupAgg = _cond_groupUnit[0]; + $scope.policy.__.groupAggPath = _cond_groupUnit[1]; + $scope.policy.__.groupAggAlias = _cond_groupUnit[4] === "aggValue" ? "" : _cond_groupUnit[4]; + $scope.policy.__.groupCondOp = _cond_groupUnit[5]; + $scope.policy.__.groupCondVal = _cond_groupUnit[6]; + } else { + $scope.policy.__.group = ""; + $scope.policy.__.groupAgg = "count"; + $scope.policy.__.groupAggPath = "timestamp"; + $scope.policy.__.groupCondOp = ">="; + $scope.policy.__.groupCondVal = "2"; + } + } catch(err) { + $scope.policy.__.window = "externalTime"; + } + } + } + + $scope.changeStep(0, 2, false); + console.log($scope.policy); + }); + } + }); + + // ========================================== + // = Function = + // ========================================== + // UI: Highlight select step + $scope.stepSelect = function(step) { + return step === $scope.step ? "active" : ""; + }; + + // UI: Collapse all + $scope.collapse = function(cntr) { + var _list = $(cntr).find(".collapse").css("height", "auto"); + if(_list.hasClass("in")) { + _list.removeClass("in"); + } else { + _list.addClass("in"); + } + }; + + // Step process. Will fetch target step attribute and return boolean + function _check(key, step) { + var _step = $scope.steps[step - 1]; + if(!_step) return; + + var _value = _step[key]; + if(typeof _value === "function") { + return _value(); + } else if(typeof _value === "boolean") { + return _value; + } + return true; + } + // Check step is ready. Otherwise will display load animation + $scope.stepReady = function(step) { + return _check("ready", step); + }; + // Check whether process next step. Otherwise will disable next button + $scope.checkNextable = function(step) { + return !_check("nextable", step); + }; + // Switch step + $scope.changeStep = function(step, targetStep, check) { + if(check === false || _check("checkStep", step)) { + $scope.step = targetStep; + + _check("init", targetStep); + } + }; + + // Window + $scope.getWindow = function() { + if(!$scope.policy || !$scope.policy.__) return null; + return common.array.find($scope.policy.__.window, $scope.config.window, "type"); + }; + + // Aggregation + $scope.groupAggPathList = function() { + return $.grep(common.getValueByPath($scope, "_stream.metas", []), function(meta) { + return $.inArray(meta.attrType, ['long','integer','number', 'double', 'float']) !== -1; + }); + }; + + $scope.updateGroupAgg = function() { + $scope.policy.__.groupAggPath = $scope.policy.__.groupAggPath || common.getValueByPath($scope.groupAggPathList()[0], "tags.attrName"); + + if($scope.policy.__.groupAgg === 'count') { + $scope.policy.__.groupAggPath = 'timestamp'; + } + }; + + // Resolver + $scope.resolverTypeahead = function(value, resolver) { + var _resolverList = Entities.query("stream/attributeresolve", { + site: Site.current().tags.site, + resolver: resolver, + query: value + }); + return _resolverList._promise.then(function() { + return _resolverList; + }); + }; + + // Used for input box when pressing enter + $scope.conditionPress = function(event) { + if(event.which == 13) { + setTimeout(function() { + $(event.currentTarget).closest(".input-group").find("button").click(); + }, 1); + } + }; + // Check whether has condition + $scope.hasCondition = function(key, type) { + var _list = common.getValueByPath($scope.policy.__.conditions, key, []); + if(_list.length === 0) return false; + + if(type === "bool") { + return !_list[0].ignored(); + } + return true; + }; + // Condition unit definition + $scope._CondUnit = function(key, op, value, type) { + return { + key: key, + op: op, + val: value, + type: type, + ignored: function() { + return this.type === "bool" && this.val === "none"; + }, + getVal: function() { + return this.type === "string" ? "'" + this.val + "'" : this.val; + }, + toString: function() { + return this.op + " " + this.getVal(); + }, + toCondString: function() { + var _op = this.op === "=" ? "==" : this.op; + if(_op === "regex") { + return "str:regexp(" + this.key + "," + this.getVal() + ")==true"; + } else if(_op === "contains") { + return "str:contains(" + this.key + "," + this.getVal() + ")==true"; + } else { + return this.key + " " + _op + " " + this.getVal(); + } + } + }; + }; + // Add condition for policy + $scope.addCondition = function(key, op, value, type) { + if(value === "" || value === undefined) return false; + + var _condList = $scope.policy.__.conditions[key] = $scope.policy.__.conditions[key] || []; + _condList.push($scope._CondUnit(key, op, value, type)); + return true; + }; + // Convert condition list to description string + $scope.parseConditionDesc = function(key) { + return $.map($scope.policy.__.conditions[key] || [], function(cond) { + if(!cond.ignored()) return "[" + cond.toString() + "]"; + }).join(" or "); + }; + + // To query + $scope.toQuery = function() { + if(!$scope.policy.__) return ""; + + if($scope.policy.__.advanced) return $scope.policy.__._expression; + + // > Query + var _query = $.map(common.getValueByPath($scope.policy, "__.conditions", {}), function(list) { + var _conds = $.map(list, function(cond) { + if(!cond.ignored()) return cond.toCondString(); + }); + if(_conds.length) { + return "(" + _conds.join(" or ") + ")"; + } + }).join(" and "); + if(_query) { + _query = "[" + _query + "]"; + } + + // > Window + var _window = $scope.getWindow(); + var _windowStr = ""; + if($scope.policy.__.windowConfig) { + _windowStr = $.map(_window.fields, function(field) { + return field.val; + }).join(","); + _windowStr = "#window." + _window.type + "(" + _windowStr + ")"; + + // > Group + if($scope.policy.__.group) { + _windowStr += common.template(" select ${group}, ${groupAgg}(${groupAggPath}) as ${groupAggAlias} group by ${group} having ${groupAggAlias} ${groupCondOp} ${groupCondVal}", { + group: $scope.policy.__.group, + groupAgg: $scope.policy.__.groupAgg, + groupAggPath: $scope.policy.__.groupAggPath, + groupCondOp: $scope.policy.__.groupCondOp, + groupCondVal: $scope.policy.__.groupCondVal, + groupAggAlias: $scope.policy.__.groupAggAlias || "aggValue" + }); + } else { + _windowStr += common.template(" select ${groupAgg}(${groupAggPath}) as ${groupAggAlias} having ${groupAggAlias} ${groupCondOp} ${groupCondVal}", { + groupAgg: $scope.policy.__.groupAgg, + groupAggPath: $scope.policy.__.groupAggPath, + groupCondOp: $scope.policy.__.groupCondOp, + groupCondVal: $scope.policy.__.groupCondVal, + groupAggAlias: $scope.policy.__.groupAggAlias || "aggValue" + }); + } + } else { + _windowStr = " select *"; + } + + return common.template("from ${stream}${query}${window} insert into outputStream;", { + stream: $scope.policy.__.streamName, + query: _query, + window: _windowStr + }); + }; + + // ========================================== + // = Update Policy = + // ========================================== + // dedupeDef notificationDef policyDef + $scope.finishPolicy = function() { + $scope.lock = true; + + // dedupeDef + $scope.policy.dedupeDef = JSON.stringify($scope.policy.__.dedupe); + + // notificationDef + $scope.policy.__.notification = $scope.policy.__.notification || []; + var _notificationUnit = $scope.policy.__.notification[0]; + if(_notificationUnit) { + _notificationUnit.flavor = "email"; + _notificationUnit.id = "email_1"; + _notificationUnit.tplFileName = ""; + } + $scope.policy.notificationDef = JSON.stringify($scope.policy.__.notification); + + // policyDef + $scope.policy.__._dedupTags = $scope.policy.__._dedupTags || {}; + $scope.policy.__.policy = { + expression: $scope.toQuery(), + type: "siddhiCEPEngine" + }; + $scope.policy.policyDef = JSON.stringify($scope.policy.__.policy); + + // alertExecutorId + if($scope._stream.alertExecutor) { + $scope.policy.tags.alertExecutorId = $scope._stream.alertExecutor.tags.alertExecutorId; + } else { + $scope.lock = false; + $.dialog({ + title: "OPS!", + content: "Alert Executor not defined! Please check 'AlertExecutorService'!" + }); + return; + } + + // site + $scope.policy.tags.site = $scope.policy.tags.site || Site.current().tags.site; + + // owner + $scope.policy.owner = Authorization.userProfile.username; + + // Update function + function _updatePolicy() { + Entities.updateEntity("AlertDefinitionService", $scope.policy)._promise.success(function(data) { + $.dialog({ + title: "Success", + content: (create ? "Create" : "Update") + " success!" + }, function() { + if(data.success) { + location.href = "#/common/policyList"; + } else { + $.dialog({ + title: "OPS", + content: (create ? "Create" : "Update") + "failed!" + JSON.stringify(data) + }); + } + }); + + $scope.create = create = false; + $scope.encodedRowkey = data.obj[0]; + }).error(function(data) { + $.dialog({ + title: "OPS", + content: (create ? "Create" : "Update") + "failed!" + JSON.stringify(data) + }); + }).then(function() { + $scope.lock = false; + }); + } + + // Check if already exist + if($scope.create) { + var _checkList = Entities.queryEntities("AlertDefinitionService", { + alertExecutorId: $scope.policy.tags.alertExecutorId, + policyId: $scope.policy.tags.policyId, + policyType: "siddhiCEPEngine", + dataSource: $scope.policy.tags.dataSource + }); + _checkList._promise.then(function() { + if(_checkList.length) { + $.dialog({ + title: "Override Confirm", + content: "Already exists PolicyID '" + $scope.policy.tags.policyId + "'. Do you want to override?", + confirm: true + }, function(ret) { + if(ret) { + _updatePolicy(); + } else { + $scope.lock = false; + $scope.$apply(); + } + }); + } else { + _updatePolicy(); + } + }); + } else { + _updatePolicy(); + } + }; + }); + } + + feature.controller('policyCreate', function(PageConfig, Site, Policy, $scope, $wrapState, $q, Entities, Application, Authorization) { + var _args = [true]; + _args.push.apply(_args, arguments); + policyCtrl.apply(this, _args); + }, "policyEdit"); + feature.controller('policyEdit', function(PageConfig, Site, Policy, $scope, $wrapState, $q, Entities, Application, Authorization) { + PageConfig.lockSite = true; + var _args = [false]; + _args.push.apply(_args, arguments); + policyCtrl.apply(this, _args); + }); + + // ============================================================== + // = Alerts = + // ============================================================== + + // ========================= Alert List ========================= + feature.navItem("alertList", "Alerts", "exclamation-triangle"); + feature.controller('alertList', function(PageConfig, Site, $scope, $wrapState, $interval, $timeout, Entities, Application) { + PageConfig.pageSubTitle = Site.current().tags.site; + + var MAX_PAGESIZE = 10000; + + // Initial load + $scope.application = Application.current(); + + $scope.alertList = []; + $scope.alertList.ready = false; + + // Load data + function _loadAlerts() { + if($scope.alertList._promise) { + $scope.alertList._promise.abort(); + } + + var _list = Entities.queryEntities("AlertService", { + site: Site.current().tags.site, + dataSource: $scope.application.tags.application, + hostname: null, + _pageSize: MAX_PAGESIZE, + _duration: 1000 * 60 * 60 * 24 * 30, + __ETD: 1000 * 60 * 60 * 24 + }); + $scope.alertList._promise = _list._promise; + _list._promise.then(function() { + var index; + + if($scope.alertList[0]) { + // List new alerts + for(index = 0 ; index < _list.length ; index += 1) { + var _alert = _list[index]; + _alert.__new = true; + if(_alert.encodedRowkey === $scope.alertList[0].encodedRowkey) { + break; + } + } + + if(index > 0) { + $scope.alertList.unshift.apply($scope.alertList, _list.slice(0, index)); + + // Clean up UI highlight + $timeout(function() { + $.each(_list, function(i, alert) { + delete alert.__new; + }); + }, 100); + } + } else { + // List all alerts + $scope.alertList.push.apply($scope.alertList, _list); + } + + $scope.alertList.ready = true; + }); + } + + _loadAlerts(); + var _loadInterval = $interval(_loadAlerts, app.time.refreshInterval); + $scope.$on('$destroy',function(){ + $interval.cancel(_loadInterval); + }); + }); + + // ========================= Alert List ========================= + feature.controller('alertDetail', function(PageConfig, Site, $scope, $wrapState, Entities) { + PageConfig.pageTitle = "Alert Detail"; + PageConfig.lockSite = true; + PageConfig + .addNavPath("Alert List", "/common/alertList") + .addNavPath("Alert Detail"); + + $scope.common = common; + + // Query policy + $scope.alertList = Entities.queryEntity("AlertService", $wrapState.param.filter); + $scope.alertList._promise.then(function() { + if($scope.alertList.length === 0) { + $.dialog({ + title: "OPS!", + content: "Alert not found!" + }, function() { + location.href = "#/common/alertList"; + }); + } else { + $scope.alert = $scope.alertList[0]; + Site.current(Site.find($scope.alert.tags.site)); + console.log($scope.alert); + } + }); + + // UI + $scope.getMessageTime = function(alert) { + var _time = common.getValueByPath(alert, "alertContext.properties.timestamp"); + return Number(_time); + }; + }); +})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/common/page/alertDetail.html ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/common/page/alertDetail.html b/eagle-webservice/src/main/webapp/app/public/feature/common/page/alertDetail.html new file mode 100644 index 0000000..fee5ab1 --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/common/page/alertDetail.html @@ -0,0 +1,61 @@ + +
+
+

+ {{alert.tags.policyId}} + {{common.format.date(alert.timestamp)}} +

+
+ +
+ View Policy + +
+
Site
{{alert.tags.site}}
+
Data Source
{{alert.tags.dataSource}}
+
+
+
Alert Time
{{common.format.date(alert.timestamp)}}
+
Message Time
{{common.format.date(alert.alertContext.properties.timestamp)}}
+
+ +
+
Stream Name
{{alert.tags.sourceStreams}}
+
+
+
Alert Source
{{alert.tags.alertSource}}
+
+
+
User
{{alert.alertContext.properties.user}}
+
Host
{{alert.alertContext.properties.host}}
+
+
+
Event
{{alert.alertContext.properties.alertEvent}}
+
+
+
Message
{{alert.alertContext.properties.alertMessage}}
+
+
+ +
+ +
+
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/common/page/alertList.html ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/common/page/alertList.html b/eagle-webservice/src/main/webapp/app/public/feature/common/page/alertList.html new file mode 100644 index 0000000..44f5a32 --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/common/page/alertList.html @@ -0,0 +1,69 @@ + +
+
+ +

+ {{application.displayName}} +

+
+
+

+ + Loading... +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Alert TimeMessage TimeData SourcePolicy NameUserHostDescription
{{common.format.date(item.timestamp)}}{{common.format.date(item.alertContext.properties.timestamp)}}{{item.tags.dataSource}} + + {{item.tags.policyId}} + {{item.alertContext.properties.user}}{{item.alertContext.properties.host}}{{item.alertContext.properties.alertMessage}}Detail
+
+ +
+ +
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/common/page/dataSrcConfig.html ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/common/page/dataSrcConfig.html b/eagle-webservice/src/main/webapp/app/public/feature/common/page/dataSrcConfig.html new file mode 100644 index 0000000..ba4f728 --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/common/page/dataSrcConfig.html @@ -0,0 +1,125 @@ +
+
+

{{_site.name}}

+
+ + +
+
+
+
+
+
+ +
+ + {{dataSrc.desc || dataSrc.tags.dataSource}} + + - + + + {{getPolicyCount(_site.name, dataSrc.tags.dataSource)}} + Policies + +
+
+
+ - + + + {{getAlertCount(_site.name, dataSrc.tags.dataSource)}} + alerts in 30 Days + +
+
+
+
+
+
+ + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyDetail.html ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyDetail.html b/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyDetail.html new file mode 100644 index 0000000..8670839 --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyDetail.html @@ -0,0 +1,172 @@ + + +
+
+

+ {{policy.tags.policyId}} + {{policy.tags.site}} +

+
+ +
+
+
+
+
Data Source
{{policy.tags.dataSource}}
+
Status
+ Enabled + Disabled +
+
+
+
Description
{{policy.desc}}
+
+
+
Alert
+ {{mail}} +
+
+
+
+ Edit + + + +
+
+
+ +
+ +
+ + +
+ + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyEdit.html ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyEdit.html b/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyEdit.html new file mode 100644 index 0000000..e07cb0c --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyEdit.html @@ -0,0 +1,359 @@ + +
+
+
+
+ + +
+
+
+
+

{{$index + 1}}

+

Step {{$index + 1}}

+

{{step.title}}

+
+
+
+ + +
+
+

Step {{step}} - {{steps[step - 1].title}}

+
+ +
+ + + + + + +
+
+ or + Advanced +
+ +
+ + + +
+ +
+ +
+
+ + +
+ +
+ + expand / collapse all + +
+
+ +
+
+
    +
  • + [X] + {{cond.toString()}} +
  • +
+ + +
+
+
+ +
+ + + + + + + + + +
+
+ + +
+
+
+ +
+ + + + + +
+
+ + +
+ +
+
+
+
+
+
+ + +
+ +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+ + +
+
+
+ + +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ +

+ +

+
+
+
+ +
+ Advanced De-Dup +
+ +
+
+ +
+
+
+
+ +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + + View Query + +
+
{{toQuery()}}
+
+
+ + +
+ +
+ +
+ + +
+
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyList.html ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyList.html b/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyList.html new file mode 100644 index 0000000..d7141a6 --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/common/page/policyList.html @@ -0,0 +1,84 @@ + +
+
+ +

+ {{application.displayName}} +

+
+
+
+
+ +
+
+
+
Enabled
+
Disabled
+
+
+ +
+ +

+ + Loading... +

+ +
+ + + + + + + + + + + + + + + + + + + + + +
Policy NameDescriptionOwnerLast ModifiedAction
{{item.tags.policyId}}{{item.desc}}{{item.owner}}{{common.format.date(item.lastModifiedDate) || "-"}} + + + + +
+
+
+ +
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/metadata/controller.js ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/metadata/controller.js b/eagle-webservice/src/main/webapp/app/public/feature/metadata/controller.js new file mode 100644 index 0000000..2797223 --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/metadata/controller.js @@ -0,0 +1,66 @@ +/* + * 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 featureControllers = angular.module('featureControllers'); + var feature = featureControllers.register("metadata"); + + // ============================================================== + // = Function = + // ============================================================== + + // ============================================================== + // = Metadata = + // ============================================================== + + // ======================= Policy Summary ======================= + feature.navItem("streamList", "Metadata", "bullseye"); + feature.controller('streamList', function(PageConfig, Site, $scope, $q, Application, Entities) { + PageConfig.hideSite = true; + + $scope.streams = {}; + $scope._streamEntity = null; + $scope._streamEntityLock = false; + + // =========================================== List =========================================== + var _streamList = Entities.queryEntities("AlertStreamService", {dataSource: Application.current().tags.application}); + var _streamSchemaList = Entities.queryEntities("AlertStreamSchemaService", {dataSource: Application.current().tags.application}); + $scope.streamList = _streamList; + $scope.streamSchemaList = _streamSchemaList; + + _streamList._promise.then(function() { + $.each(_streamList, function(i, stream) { + stream.metaList = []; + $scope.streams[stream.tags.dataSource + "_" + stream.tags.streamName] = stream; + }); + }); + + $q.all([_streamList._promise, _streamSchemaList._promise]).then(function() { + $.each(_streamSchemaList, function(i, meta) { + var _stream = $scope.streams[meta.tags.dataSource + "_" + meta.tags.streamName]; + if(_stream) { + _stream.metaList.push(meta); + } else { + console.warn("[Meta] Stream not match:", meta.tags.dataSource + "_" + meta.tags.streamName); + } + }); + }); + }); +})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/d37643b0/eagle-webservice/src/main/webapp/app/public/feature/metadata/page/streamList.html ---------------------------------------------------------------------- diff --git a/eagle-webservice/src/main/webapp/app/public/feature/metadata/page/streamList.html b/eagle-webservice/src/main/webapp/app/public/feature/metadata/page/streamList.html new file mode 100644 index 0000000..9218d8d --- /dev/null +++ b/eagle-webservice/src/main/webapp/app/public/feature/metadata/page/streamList.html @@ -0,0 +1,84 @@ + +

+ + Loading... +

+ +
+
+

{{stream.tags.streamName}}

+
+
+
+
+
+ Data Source +
+
+ {{stream.tags.dataSource}} +
+
+
+
+ Stream Name +
+
+ {{stream.tags.streamName}} +
+
+
+
+
+
+ Description +
+
+ {{stream.desc}} +
+
+
+ +

+ + Loading... +

+ +
+ + + + + + + + + + + + + + + + + +
Attribute NameDisplay NameTypeDescription
{{meta.tags.attrName}}{{meta.attrDisplayName}}{{meta.attrType}}{{meta.attrDescription}}
+
+
+ +
\ No newline at end of file