[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.
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>
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 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 @@
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 @@
}
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;
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.LoggerFactory;
import java.util.*;
+import javax.validation.Valid;
import javax.ws.rs.*;
/**
@@ -206,7 +207,7 @@
@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);
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
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
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>
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;
});