Repository: incubator-eagle Updated Branches: refs/heads/master 21fcd7333 -> 77524c7c4
[EAGLE-716][API] Forcefully Validate before saving policy into metadata https://issues.apache.org/jira/browse/EAGLE-716 [API] Forcefully Validate before saving policy into metadata when calling POST /policies Author: Hao Chen <h...@apache.org> Closes #593 from haoch/validateBeforeCreatingPolicy. Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/77524c7c Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/77524c7c Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/77524c7c Branch: refs/heads/master Commit: 77524c7c4f8e3a186bb1fb5c802b73a582585e5b Parents: 21fcd73 Author: Hao Chen <h...@apache.org> Authored: Wed Nov 2 10:21:23 2016 +0800 Committer: Hao Chen <h...@apache.org> Committed: Wed Nov 2 10:21:23 2016 +0800 ---------------------------------------------------------------------- .../metadata/resource/MetadataResource.java | 7 ++- .../eagle/alert/metadata/resource/OpResult.java | 21 +++++++ .../partials/alert/policyEdit/advancedMode.html | 58 +++++++++++--------- 3 files changed, 60 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/77524c7c/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 45ffa2d..2a2047f 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 @@ -202,7 +202,12 @@ public class MetadataResource { @Path("/policies") @POST public OpResult addPolicy(PolicyDefinition policy) { - return dao.addPolicy(policy); + PolicyValidationResult validationResult = this.validatePolicy(policy); + if (validationResult.isSuccess()) { + return dao.addPolicy(policy); + } else { + return OpResult.fail(validationResult.getMessage()); + } } @Path("/policies/validate") http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/77524c7c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java index a43b064..9f5ce7f 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java @@ -26,4 +26,25 @@ public class OpResult { public static final int SUCCESS = 200; public static final int FAILURE = 500; + + public static OpResult of(int code, String messsage) { + OpResult opResult = new OpResult(); + opResult.code = code; + opResult.message = messsage; + return opResult; + } + + public static OpResult success(String messsage) { + OpResult opResult = new OpResult(); + opResult.code = SUCCESS; + opResult.message = messsage; + return opResult; + } + + public static OpResult fail(String messsage) { + OpResult opResult = new OpResult(); + opResult.code = FAILURE; + opResult.message = messsage; + return opResult; + } } http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/77524c7c/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 7c3d4f1..5097d33 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 @@ -82,37 +82,25 @@ <div class="box box-primary"> <div class="box-header with-border"> <span class="fa fa-pencil"></span> - <h3 class="box-title">Policy</h3> + <h3 class="box-title">Policy Editor</h3> </div> <div class="box-body"> + + <div class="row"> - <div class="col-md-8"> - <div class="form-group"> - <label>* Name</label> - <input type="text" class="form-control" ng-model="policy.name" ng-readonly="!newPolicy" ng-disabled="policyLock" /> - </div> - </div> - <div class="col-md-4"> + <div class="col-md-12"> <div class="form-group"> - <label>* Parallelism Hint</label> - <input type="text" class="form-control" ng-model="policy.parallelismHint" ng-disabled="policyLock" /> + <label>Name *</label> + <input type="text" style="text-transform:uppercase" 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> </div> - <div class="form-group" ng-class="{'has-error': !!definitionMessage}"> - <label>* Definition</label> - <div editor ng-model="policy.definition.value" ng-change="checkDefinition()"></div> - <!--textarea class="form-control" ng-model="policy.definition.value" rows="10" ng-change="checkDefinition()" ng-disabled="policyLock"></textarea--> - <p class="text-danger">{{definitionMessage}}</p> - </div> - <!--label> Input Stream Partition </label> @@ -135,9 +123,19 @@ </li> </ul--> - <label> - Alert Stream - </label> + <div class="form-group" ng-class="{'has-error': !!definitionMessage}"> + <label>Policy Definition *</label> + <div editor ng-model="policy.definition.value" ng-change="checkDefinition()"></div> + <!--textarea class="form-control" ng-model="policy.definition.value" rows="10" ng-change="checkDefinition()" ng-disabled="policyLock"></textarea--> + <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 ng-repeat="stream in outputStreams track by $index"> <label> @@ -145,12 +143,14 @@ {{stream}} </label> </li> - <li class="text-danger" ng-if="policy.outputStreams.length === 0">No alert stream yet.</li> </ul> <label> - Publisher + 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 ng-repeat="publisher in policyPublisherList track by $index"> <span> @@ -165,11 +165,19 @@ <span>{{publisher.properties[field]}}</span> </p> </li> - <li class="text-danger" ng-if="policyPublisherList.length === 0">No publisher yet.</li> <li> <a ng-click="addPublisher()">+ Add Publisher</a> </li> </ul> + + <div class="row"> + <div class="col-md-12"> + <div class="form-group"> + <label>Schedule Parallelism *</label> + <input type="text" class="form-control" ng-model="policy.parallelismHint" ng-disabled="policyLock" /> + </div> + </div> + </div> </div> </div> </div> @@ -178,7 +186,7 @@ <div class="text-right"> <button class="btn btn-primary" ng-disabled="!saveCheck()" ng-click="saveConfirm()"> <span class="fa fa-floppy-o"></span> - Save + Apply </button> </div>