SLA plugin updated
authorjavier <javier.garcial.external@atos.net>
Mon, 16 Jun 2014 15:55:03 +0000 (17:55 +0200)
committerjavier <javier.garcial.external@atos.net>
Mon, 16 Jun 2014 15:55:03 +0000 (17:55 +0200)
plugins/queryupdater/static/js/queryupdater.js
plugins/sladialog/static/js/sladialog.js
plugins/sladialog/templates/sladialog.html
portal/templates/fed4fire/fed4fire_widget-slice-sections.html
sla/slicetabsla.py

index ab6465c..bf650bb 100644 (file)
@@ -35,6 +35,7 @@
             var self = this;
 
             this.initial = Array();
+            this.selected_resources = Array();
 
             this.table = this.elmt('table').dataTable({
 // the original querytable layout was
@@ -43,7 +44,7 @@
                 sDom: "<'row'<'col-xs-5'l><'col-xs-1'r><'col-xs-6'f>>t>",
 // so this does not matter anymore now that the pagination area is turned off
 //                sPaginationType: 'bootstrap',
-               bAutoWidth: true,
+                     bAutoWidth: true,
 //                bJQueryUI      : true,
 //                bRetrieve      : true,
 //                sScrollX       : '100%',                 // Horizontal scrolling 
         do_checksla: function(e) {
             var username = e.data.options.username;
             var urn = data.value;
+            var arrayselectedresources = data.selected_resources;
+
+            var accepted_sla = Array();
+            var count = 0;
             // XXX check that the query is not disabled
 
             console.log("DATA VALUE: " + data.value);
+            
+            //<p>SLA description</p>
+            //<p>Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime</p>
+            //<p>SLA description</p>
+            //<p>Testbed guarantees 0.99 Uptime rate for 0.99 rate of the WiLab2 resources during the sliver lifetime</p>
+            var promt = $('#modal-body');
+            
+            // id="myModalLabel"
+            var flagVW = false;
+            var  flagWi = false;
+
+            var wilabForm = "";
+            var wimessage = '<p>SLA description</p><p>to be deployed</p>';
+            for(var iter = 0; iter < arrayselectedresources.length; iter++){
+                var list = '<p class="wi'+iter+'" name=wi"'+iter+'">'+arrayselectedresources[iter].toLowerCase()+'</p><br>';
+                
 
-            if (data.value.toLowerCase().indexOf("iminds") >= 0){
+                if (arrayselectedresources[iter].toLowerCase().indexOf("wilab2") >= 0){
 
-                $('#sla_dialog').show();
-                $('#slamodal').modal('show');
+                    accepted_sla.push({"wilab2":false}); 
+                    wilabForm += list;   
+                    flagWi = true;             
+
+                }
+
+            }
+
+            //var wallmessage = '<p>SLA description</p><p>Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime</p>';
+
+            var wallForm = "";
+            for(var iter = 0; iter < arrayselectedresources.length; iter++){
+                var list = '<class="wall'+iter+'" name=wall"'+iter+'" >'+arrayselectedresources[iter].toLowerCase()+'</p><br>';
                 
-                $(document).ready(function() {
-                    $("#accept_sla").click(function(){
-                        console.log("SLA ACCEPTED");
-                        console.log("With username: " + username);
-                        if(urn.toLowerCase().indexOf("wall2") >= 0){ 
-                            $.post("/sla/agreements/simplecreate", 
-                                { "template_id": "iMindsServiceVirtualwall",
-                                  "user": username,
-                                  "expiration_time": new Date() // jgarcia: FIXME
-                                });
-                        } else if(urn.toLowerCase().indexOf("wilab2") >= 0){
-                            $.post("/sla/agreements/simplecreate", 
-                                { "template_id":"iMindsServiceWiLab2",
-                                  "user":username,
-                                  "expiration_time": new Date() // jgarcia: FIXME
-                                });
-                        }
-                        $('#slamodal').modal('hide');
-                        self.spin();
-                        console.log("Executing do_update after sending SLA");
-                        // XXX check that the query is not disabled
-                        manifold.raise_event(self.options.query_uuid, RUN_UPDATE);
-
-                        // how to stop the spinning after the event? 
-                        // this should be triggered by some on_updatequery_done ?
-                    }); 
-                });
-
-                $(document).ready(function() {
-                    $("#dismiss_sla").click(function(){
-                        console.log("SLA NOT ACCEPTED");
-                        $('#slamodal').modal('hide');
-                    }); 
-                });
+                if (arrayselectedresources[iter].toLowerCase().indexOf("wall2") >= 0){
 
-            } else {
-                self.spin();
-                console.log("do_update");
-                // XXX check that the query is not disabled
-                manifold.raise_event(self.options.query_uuid, RUN_UPDATE);
+                    accepted_sla.push({"wall2":false});
+                    wallForm += list;
+                    flagVW = true;
+                    
+                }
 
-                // how to stop the spinning after the event? 
-                // this should be triggered by some on_updatequery_done ?
             }
+            promt.append(wimessage);
+            var flagDouble = false;
+            if(flagWi)
+            {
+                flagDouble = true;
+                promt.append(wilabForm);
+            }
+            if(flagVW)
+            {
+                //promt.append(wallmessage);
+                flagDouble = true;
+                promt.append(wallForm);
+            }
+
+                        
+            // var wimessage = '<p>SLA description</p><p>Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime</p>'
+
+                $('#sla_dialog').show();
+                    $('#slamodal-wilab2').modal('show');
+                    
+                    
+                        $("#accept_sla_wilab2").click(function(){
+                            console.log("SLA ACCEPTED");
+                            console.log("With username: " + username);
+
+                            // var promt = $('#modal-body');
+                            // var notchecked = true;
+                            // for (var i=0;i<50;i++)
+                            // {
+                            //     var wielement = $('#wi'+i);
+                            //     var wallElement = $('#wall'+i);
+                            //     if(wielement != null && !wielement.checked)
+                            //     {
+                            //         notchecked = false;
+                            //     }
+                            //     if(wallElement!= null && !wallElement.checked)
+                            //     {
+                            //         notchecked = false;
+                            //     }
+                            // }
+            
+                                                       
+                                if(flagDouble)
+                                {
+                                    $.post("/sla/agreements/simplecreate", 
+                                        { "template_id": "iMindsServiceWiLab2",
+                                          "user": username,
+                                          "expiration_time": new Date().toISOString()
+                                       });
+                                     $.post("/sla/agreements/simplecreate", 
+                                        { "template_id": "iMindsServiceVirtualwall",
+                                          "user": username,
+                                          "expiration_time": new Date().toISOString()
+                                       });
+                            
+                                    $('#slamodal-wilab2').modal('hide');
+                                accepted_sla["wilab2"] = true;
+                            
+                                //this.do_update(e);
+                            }
+                        }); 
+                    
+                        $("#dismiss_sla_wilab2").click(function(){
+                            console.log("SLA NOT ACCEPTED");
+                            $('#slamodal-wilab2').modal('hide');
+                        }); 
+
+            // for(var iter = 0; iter < arrayselectedresources.length; iter++){
+            //     var list = '<input type="checkbox" name="'+iter+'" >'+arrayselectedresources[iter].toLowerCase()+'<br>';
+            //     promt.append(list);
+            //     if (arrayselectedresources[iter].toLowerCase().indexOf("wall2") >= 0){
+
+
+                    
+            //         accepted_sla.push({"wall2":false});
+
+            //         $('#sla_dialog').show();
+            //         $('#slamodal-virtualwall').modal('show');
+                    
+                    
+            //             $("#accept_sla_vwall").click(function(){
+            //                 console.log("SLA ACCEPTED");
+            //                 console.log("With username: " + username);
+                        
+            //                 $.post("/sla/agreements/simplecreate", 
+            //                     { "template_id": "iMindsServiceVirtualwall",
+            //                       "user": username,
+            //                       "expiration_time": new Date()
+            //                     });
+                        
+            //                 $('#slamodal-virtualwall').modal('hide');
+            //                 accepted_sla["wall2"] = true;
+            //             }); 
+
+            //             $("#dismiss_sla_vwall").click(function(){
+            //                 console.log("SLA NOT ACCEPTED");
+            //                 $('#slamodal-vir').modal('hide');
+            //             }); 
+                    
+            //     }
+
+            //     if (arrayselectedresources[iter].toLowerCase().indexOf("wilab2") >= 0){
+
+            //         accepted_sla.push({"wilab2":false});
+
+            //         $('#sla_dialog').show();
+            //         $('#slamodal-wilab2').modal('show');
+                    
+                    
+            //             $("#accept_sla_wilab2").click(function(){
+            //                 console.log("SLA ACCEPTED");
+            //                 console.log("With username: " + username);
+                        
+            //                 $.post("/sla/agreements/simplecreate", 
+            //                     { "template_id": "iMindsServiceWiLab2",
+            //                       "user": username,
+            //                       "expiration_time": new Date()
+            //                     });
+                        
+            //                 $('#slamodal-wilab2').modal('hide');
+            //                 accepted_sla["wilab2"] = true;
+            //             }); 
+                    
+            //             $("#dismiss_sla_wilab2").click(function(){
+            //                 console.log("SLA NOT ACCEPTED");
+            //                 $('#slamodal-wilab2').modal('hide');
+            //             }); 
+                    
+
+            //     }
+
+            // }
+
+            // for(var sla in accepted_sla){
+            //     if(accepted_sla[sla] == true){
+            //         count += 1;
+            //     }
+            // }
+
+            // if(count == accepted_sla.length){
+            //     this.do_update(e);
+            // }
         },
 
+     
         do_update: function(e) {
             var self = e.data;
 
             var urn = data.value;
             // XXX check that the query is not disabled
 
-            console.log("DATA VALUE: " + data.value);
-
-            if (data.value.toLowerCase().indexOf("iminds") >= 0){
-
-                $('#sla_dialog').show();
-                $('#slamodal').modal('show');
-                
-                $(document).ready(function() {
-                    $("#accept_sla").click(function(){
-                        console.log("SLA ACCEPTED");
-                        console.log("With username: " + username);
-                        if(urn.toLowerCase().indexOf("wall2") >= 0){ 
-                            $.post("/sla/agreements/simplecreate", 
-                                { "template_id": "iMindsServiceVirtualwall",
-                                  "user": username,
-                                  "expiration_time": new Date() // jgarcia: FIXME
-                                });
-                        } else if(urn.toLowerCase().indexOf("wilab2") >= 0){
-                            $.post("/sla/agreements/simplecreate", 
-                                { "template_id":"iMindsServiceWiLab2",
-                                  "user":username,
-                                  "expiration_time": new Date() // jgarcia: FIXME
-                                });
-                        }
-                        $('#slamodal').modal('hide');
-                        self.spin();
-                        console.log("Executing do_update after sending SLA");
-                        // XXX check that the query is not disabled
-                        manifold.raise_event(self.options.query_uuid, RUN_UPDATE);
-
-                        // how to stop the spinning after the event? 
-                        // this should be triggered by some on_updatequery_done ?
-                    }); 
-                });
-
-                $(document).ready(function() {
-                    $("#dismiss_sla").click(function(){
-                        console.log("SLA NOT ACCEPTED");
-                        $('#slamodal').modal('hide');
-                    }); 
-                });
-
-            } else {
-                self.spin();
-                console.log("do_update");
-                // XXX check that the query is not disabled
-                manifold.raise_event(self.options.query_uuid, RUN_UPDATE);
+            self.spin();
+            console.log("do_update");
+            // XXX check that the query is not disabled
+            //manifold.raise_event(self.options.query_uuid, RUN_UPDATE);
 
-                // how to stop the spinning after the event? 
-                // this should be triggered by some on_updatequery_done ?
-            }
+            // how to stop the spinning after the event? 
+            // this should be triggered by some on_updatequery_done ?
 
         },
 
             // XXX it's not just about adding lines, but sometimes removing some
             // XXX how do we handle status reset ?
             data.value = JSON.stringify(data.value);
+            data.selected_resources = this.selected_resources;
             row = this.find_row(data.value);
             newline = [
                 action,
         {
             console.log("on_field_state_changed");
             console.log(result);
+            if(result.request == FIELD_REQUEST_ADD){
+                this.selected_resources.push(result.value);
+            } else if(result.request == FIELD_REQUEST_REMOVE_RESET){
+                var i = this.selected_resources.indexOf(result.value);
+                if(i != -1){
+                    this.selected_resources.splice(i,1);
+                }
+            }
+            console.log("Resources: " + self.selected_resources);
             messages.debug(result)
             /* this.set_state(result.request, result.key, result.value, result.status); */
             this.set_state(result);
index 89d1ab0..1098e2e 100644 (file)
         // how to raise manifold events
         set_state: function(data, username)
         {
-            var action;
-            var msg;
-            var button = '';
-            var username = username;
-
-            var uncheck = false;
-
-            switch(data.request) {
-                case FIELD_REQUEST_ADD_RESET:
-                case FIELD_REQUEST_REMOVE_RESET:
-                    $('#sla_dialog').hide();
-                    // find line and delete it                    
-                    // row = this.find_row(data.value);
-                    // if (row)
-                    //     this.table.fnDeleteRow(row.nTr);
-                        // $("#badge-pending").data('number', $("#badge-pending").data('number') - 1 );
-                        // $("#badge-pending").text($("#badge-pending").data('number'));
-                    return;
-                case FIELD_REQUEST_CHANGE:
-                    action = 'UPDATE';
-                    break;
-                case FIELD_REQUEST_ADD:
-                    action = 'ADD';
-
-                    if (data.value.toLowerCase().indexOf("iminds") >= 0){
-
-                        $('#sla_dialog').show();
-                        $('#slamodal').modal('show');
-                        
-                        $(document).ready(function() {
-                            $("#accept_sla").click(function(){
-                                console.log("SLA ACCEPTED");
-                                console.log("With username: " + username);
-                                $.post("/sla/agreements/simplecreate", {"template_id":"iMindsServiceTemplate","user":username});
-                                $('#slamodal').modal('hide');
-                            }); 
-                        });
-
-                        $(document).ready(function() {
-                            $("#dismiss_sla").click(function(){
-                                console.log("SLA NOT ACCEPTED");
-                                // FIX ME: This is not a good solution to prevent the checkbox click
-                                var chkbox = document.getElementById((data.value).replace(/"/g,''));
-                                if(chkbox.checked){
-                                    chkbox.click();
-                                }
-                                $('#slamodal').modal('hide');
-                                
-                            }); 
-                        });
-
-                    }
-
-                    break;
-                case FIELD_REQUEST_REMOVE:
-                    action = 'REMOVE';
-                    break;
-            }
+            
         },
 
         post_agreement: function()
index 0860400..ce27c2e 100644 (file)
@@ -1,20 +1,38 @@
 <div id={{ domid }}>
-<div class="modal fade" id="slamodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
+<div class="modal fade" id="slamodal-wilab2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
                data-backdrop="static" data-keyboard="false">
   <div class="modal-dialog">
     <div class="modal-content">
       <div class="modal-header">
         <h4 class="modal-title" id="myModalLabel">Provider iMinds offers the following SLA</h4>
       </div>
-      <div class="modal-body">
-        <p>SLA description</p>
-        <p>Testbed guarantees 0.99 Uptime rate for 0.99 rate of the resources during the sliver lifetime</p>
+      <div class="modal-body"  id="modal-body">
+        <!-- <p>SLA description</p>
+        <p>Testbed guarantees 0.99 Uptime rate for 0.99 rate of the WiLab2 resources during the sliver lifetime</p> -->
       </div>
       <div class="modal-footer">
-        <button type="button" id="dismiss_sla" class="btn btn-default" data-dismiss="modal">Dismiss</button>
-        <button type="button" id="accept_sla" class="btn btn-primary">Accept</button>
+        <button type="button" id="dismiss_sla_wilab2" class="btn btn-default" data-dismiss="modal">Dismiss</button>
+        <button type="button" id="accept_sla_wilab2" class="btn btn-primary">Accept</button>
       </div>
     </div>
   </div>
 </div>
+<!-- <div class="modal fade" id="slamodal-virtualwall" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
+    data-backdrop="static" data-keyboard="false">
+  <div class="modal-dialog">
+    <div class="modal-content">
+      <div class="modal-header">
+        <h4 class="modal-title" id="modalTitleId">Provider iMinds offers the following SLA</h4>
+      </div>
+      <div class="modal-body" id="modal-body">
+        <p>SLA description</p>
+        <p>Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime</p>
+      </div>
+      <div class="modal-footer">
+        <button type="button" id="dismiss_sla_vwall" class="btn btn-default" data-dismiss="modal">Dismiss</button>
+        <button type="button" id="accept_sla_vwall" class="btn btn-primary">Accept</button>
+      </div>
+    </div>
+  </div>
+</div> -->
 </div>
index f223736..c7bd719 100644 (file)
@@ -4,6 +4,7 @@
 <!--   <li><a href="/slice/{{ slice }}#testbeds">Testbeds</a></li> -->
        <li class="active"><a class="link" href="/resources/{{ slice }}">Resources</a></li>
        <li><a href="/slice/{{ slice }}#users">Users</a></li>
+       <li class="sla"><a href="#sla" data-toggle="tab">SLA</a></li>
 
 <!--   <li><a href="/slice/{{ slice }}#experiment">Statistics</a></li> 
        <li><a href="/slice/{{ slice }}#measurements">Measurements</a></li>
@@ -20,7 +21,7 @@
        <!-- <li class="statistics"><a href="#experiment">Statistics</a></li>
        <li class="measurements"><a href="#experiment">Measurements</a></li>
        <li class="experiment"><a href="#experiment" data-toggle="tab">Experiment</a></li> -->
-       <li class="sla" style="display:none"><a href="#sla" data-toggle="tab">SLA</a></li>
+       <li class="sla"><a href="#sla" data-toggle="tab">SLA</a></li>
 
 </ul>
 <script>
index 4271858..6b350d4 100755 (executable)
@@ -343,9 +343,14 @@ class AgreementSimple(APIView):
         except:
             return self.build_response(400, 'Invalid user')
 
+        try:
+            expiration_time = data['expiration_time']
+        except:
+            return self.build_response(400, 'Invalid expiration_time')
+
         try:
             print "Calling createagreementsimplified with template_id:",template_id,"and user:",user
-            result = fed4fireservice.createagreementsimplified(template_id, user)
+            result = fed4fireservice.createagreementsimplified(template_id, user, expiration_time)
             print result
         except Exception, e:
             print traceback.format_exc()