eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject eagle git commit: [EAGLE-851] Add validation for policy name
Date Fri, 13 Jan 2017 09:05:07 GMT
Repository: eagle
Updated Branches:
  refs/heads/master 0622ae1f4 -> 3523480c4


[EAGLE-851] Add validation for policy name

- Add checkPolicyName method to check the length of policy name.

https://issues.apache.org/jira/browse/EAGLE-851

Author: r7raul1984 <tangjijun@yhd.com>

Closes #765 from r7raul1984/EAGLE-851.


Project: http://git-wip-us.apache.org/repos/asf/eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/eagle/commit/3523480c
Tree: http://git-wip-us.apache.org/repos/asf/eagle/tree/3523480c
Diff: http://git-wip-us.apache.org/repos/asf/eagle/diff/3523480c

Branch: refs/heads/master
Commit: 3523480c458b475763bf27c21c9f65929abeb478
Parents: 0622ae1
Author: r7raul1984 <tangjijun@yhd.com>
Authored: Fri Jan 13 17:04:54 2017 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Fri Jan 13 17:04:54 2017 +0800

----------------------------------------------------------------------
 .../eagle-alert/alert-common/pom.xml              |  5 +++++
 .../engine/coordinator/PolicyDefinition.java      |  8 +++++---
 .../metadata/resource/MetadataResource.java       |  3 ++-
 .../app/apps/hadoop_metric/ctrls/overview.js      |  1 -
 .../apps/hadoop_metric/ctrls/regionListCtrl.js    | 18 ------------------
 .../partials/alert/policyEdit/advancedMode.html   |  7 +++++--
 .../app/dev/public/js/ctrls/alertEditCtrl.js      | 18 +++++++++++++++++-
 7 files changed, 34 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/eagle/blob/3523480c/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml
index f5218b7..089955f 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml
@@ -102,6 +102,11 @@
             <artifactId>joda-time</artifactId>
         </dependency>
         <dependency>
+            <groupId>io.dropwizard</groupId>
+            <artifactId>dropwizard-validation</artifactId>
+            <version>${dropwizard.version}</version>
+        </dependency>
+        <dependency>
             <groupId>io.dropwizard.metrics</groupId>
             <artifactId>metrics-core</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/eagle/blob/3523480c/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/PolicyDefinition.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/PolicyDefinition.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/PolicyDefinition.java
index 02072ad..7398dd5 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/PolicyDefinition.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/PolicyDefinition.java
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.ListUtils;
 import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.hibernate.validator.constraints.Length;
 
 import java.io.Serializable;
 import java.util.*;
@@ -31,6 +32,7 @@ import java.util.*;
 public class PolicyDefinition implements Serializable {
     private static final long serialVersionUID = 377581499339572414L;
     // unique identifier
+    @Length(min = 1, max = 50, message = "length should between 1 and 50")
     private String name;
     private String description;
     private List<String> inputStreams = new ArrayList<String>();
@@ -226,9 +228,9 @@ public class PolicyDefinition implements Serializable {
             }
             Definition another = (Definition) that;
             if (another.type.equals(this.type)
-                && another.value.equals(this.value)
-                && ListUtils.isEqualList(another.inputStreams, this.inputStreams)
-                && ListUtils.isEqualList(another.outputStreams, this.outputStreams))
{
+                    && another.value.equals(this.value)
+                    && ListUtils.isEqualList(another.inputStreams, this.inputStreams)
+                    && ListUtils.isEqualList(another.outputStreams, this.outputStreams))
{
                 return true;
             }
             return false;

http://git-wip-us.apache.org/repos/asf/eagle/blob/3523480c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
index 7bfd2c3..617b4f0 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
@@ -36,6 +36,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.*;
+import javax.validation.Valid;
 import javax.ws.rs.*;
 
 /**
@@ -206,7 +207,7 @@ public class MetadataResource {
 
     @Path("/policies")
     @POST
-    public OpResult addPolicy(PolicyDefinition policy) {
+    public OpResult addPolicy(@Valid PolicyDefinition policy) {
         PolicyValidationResult validationResult = this.validatePolicy(policy);
         if (validationResult.isSuccess()) {
             return dao.addPolicy(policy);

http://git-wip-us.apache.org/repos/asf/eagle/blob/3523480c/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/overview.js
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/overview.js
b/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/overview.js
index e10a0ce..2c30cb0 100644
--- a/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/overview.js
+++ b/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/overview.js
@@ -171,4 +171,3 @@
 		});
 	});
 })();
-//# sourceURL=overview.js

http://git-wip-us.apache.org/repos/asf/eagle/blob/3523480c/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/regionListCtrl.js
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/regionListCtrl.js
b/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/regionListCtrl.js
index bc7abd9..1477e32 100644
--- a/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/regionListCtrl.js
+++ b/eagle-hadoop-metric/src/main/webapp/app/apps/hadoop_metric/ctrls/regionListCtrl.js
@@ -16,24 +16,6 @@
  * limitations under the License.
  */
 
-/*
- * 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 () {
 	/**
 	 * `register` without params will load the module which using require

http://git-wip-us.apache.org/repos/asf/eagle/blob/3523480c/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 16e210d..995a8a5 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
@@ -102,8 +102,11 @@
 
 				<div class="row">
 					<div class="col-md-12">
-						<div class="form-group">
-							<label>Name *</label>
+						<div class="form-group" ng-class="{'has-error': checkPolicyName()}">
+							<label>
+								Name *
+								<small ng-if="checkPolicyName()">({{checkPolicyName()}})</small>
+							</label>
 							<input type="text" class="form-control" ng-model="policy.name" ng-readonly="!newPolicy"
ng-disabled="policyLock" />
 						</div>
 					</div>

http://git-wip-us.apache.org/repos/asf/eagle/blob/3523480c/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 7c8e0b7..f079e76 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
@@ -304,6 +304,15 @@
 			return false;
 		};
 
+
+		$scope.checkPolicyName = function () {
+			if($scope.policy.name.length > 50) {
+				return "length should less than 50";
+			}
+			return false;
+		};
+
+
 		$scope.addPublisherConfirm = function () {
 			if($scope.addPublisherType === "exist") {
 				$scope.publisher = $.extend({
@@ -325,6 +334,7 @@
 			return (
 				!$scope.saveLock &&
 				$scope.policy.name &&
+				!$scope.checkPolicyName() &&
 				common.number.parse($scope.policy.parallelismHint) > 0 &&
 				$scope.policy.definition.value &&
 				$scope.policy.outputStreams.length &&
@@ -383,9 +393,15 @@
 							$scope.policyLock = false;
 						});
 					}, function (res) {
+						var errormsg = "";
+						if(typeof res.data.message !== 'undefined') {
+							errormsg = res.data.message;
+						} else {
+							errormsg = res.data.errors;
+						}
 						$.dialog({
 							title: "OPS",
-							content: "Create policy failed: " + res.data.message
+							content: "Create policy failed: " + errormsg
 						});
 						$scope.policyLock = false;
 					});


Mime
View raw message