create NFVO scaling function
authorLuji7 <lu.ji3@zte.com.cn>
Tue, 7 Mar 2017 06:54:26 +0000 (14:54 +0800)
committerLuji7 <lu.ji3@zte.com.cn>
Tue, 7 Mar 2017 06:54:41 +0000 (14:54 +0800)
commit gui code for scaling function

Issue-ID: CLIENT-168
Change-Id: I1bd4609fb2ac324f497c5a044543890980f8f4a3
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js
lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js
lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html

index 8cc47b0..8251458 100644 (file)
@@ -124,7 +124,10 @@ app.factory("DataService", function($http, $log){
         
         deleteService : function(serviceId) {
             return deleteServiceInstance(serviceId);    
-        }   
+        },
+        scaleService: function (nsInstanceId, scaleType, aspectId, numberOfSteps, resultHandleFun) {
+            scaleServiceInstance(nsInstanceId, scaleType, aspectId, numberOfSteps, resultHandleFun);
+        }
     }
 });
 
@@ -756,4 +759,106 @@ function queryServiceData(){
             }
         });
     return returnVal;
+}
+
+function scaleServiceInstance(nsInstanceId, scaleType, aspectId, numberOfSteps, resultHandleFun) {
+    var parameter = {
+        'nsInstanceId': nsInstanceId,
+        'scaleType': 'SCALE_NS',
+        'scaleNsData': [
+            {
+                'scaleNsByStepsData': [
+                    {
+                        'scalingDirection': scaleType,
+                        'aspectId': aspectId,
+                        'numberOfSteps': numberOfSteps
+                    }
+                ]
+            }
+        ]
+    };
+    var nfvoUri = '/openoapi/nslcm/1.0/ns/' + nsInstanceId + '/scale';
+    $.when(
+        $.ajax({
+            type: "POST",
+            url: nfvoUri,
+            contentType: "application/json",
+            dataType: "json",
+            data: JSON.stringify(parameter)
+        })
+    ).then(
+        function (response) {
+            var jobId = response.jobID;
+            //show the progress dialog
+            return queryScaleProgress(jobId);
+        }
+    ).then(function (response) {
+        resultHandleFun(response);
+    });
+}
+
+function queryScaleProgress(jobId) {
+    //show the progress dialog
+    var operation = 'scale network service';
+    $("#idScaleProgressTitle").text(operation);
+    $("#scaleProgressContent").text('status:');
+    $("#scaleProgressbar").attr("style", "width: 0%");
+    $("#scaleProgressDialog").modal({backdrop: 'static', keyboard: false});
+    //set a timer for query operation
+    var defer = $.Deferred();
+    var queryProgressUri = jobStatusUri(jobId);
+    var timerDefer = $.Deferred();
+    var timeout = 3600000;
+    var fun = function () {
+        if (timeout === 0) {
+            timerDefer.resolve({
+                status: 'error',
+                reason: operation + ' timeout!',
+            });
+            return;
+        }
+        timeout = timeout - 1000;
+        $.when($.ajax({
+            type: "GET",
+            url: queryProgressUri
+        }))
+            .then(function (response) {
+                //update progress
+                $("#scaleProgressbar").attr("style", "width: " + response.responseDescriptor.progress.toString() + "%");
+                $("#scaleProgressValue").text(response.responseDescriptor.progress.toString() + '%');
+                $("#scaleProgressContent").text('status: ' + response.responseDescriptor.statusDescription);
+                if (response.responseDescriptor.status == 'finished' || response.responseDescriptor.status == 'error') {
+                    timerDefer.resolve({
+                        status: response.responseDescriptor.status,
+                        reason: response.responseDescriptor.errorCode
+                    });
+                }
+            });
+    };
+    var timerId = setInterval(fun, 1000);
+    $.when(timerDefer)
+        .then(function (responseDesc) {
+            clearInterval(timerId);
+            $('#scaleProgressDialog').modal('hide');
+            defer.resolve({
+                status: responseDesc.status,
+                reason: responseDesc.reason
+            });
+
+        });
+    return defer;
+}
+
+/**
+ * generate url for querying operation status
+ * @param jobId
+ * @param responseId
+ * @returns
+ */
+function jobStatusUri(jobId, responseId) {
+    var responsePara = '';
+    if (undefined !== responseId) {
+        responsePara = '&responseId=' + responseId;
+    }
+    return '/openoapi/nslcm/v1/jobs/' + jobId + responsePara;
 }
\ No newline at end of file
index 75541d0..3fceb57 100644 (file)
@@ -139,6 +139,20 @@ var app = angular.module("lcApp", ["ui.router", "ngTable"])/*, 'ui.bootstrap', '
                 }, function (reason) {\r
                     $scope.error = "Error ! " + reason;\r
                 });\r
+            $('#scalingTypeIn').on("change", function (e) {\r
+                var value = $(e.target).val();\r
+                if ('on' === value) {\r
+                    $('#scalingTypeIn').attr("checked", "checked");\r
+                    $('#scalingTypeOut').removeAttr("checked");\r
+                }\r
+            });\r
+            $('#scalingTypeOut').on("change", function (e) {\r
+                var value = $(e.target).val();\r
+                if ('on' === value) {\r
+                    $('#scalingTypeOut').attr("checked", "checked");\r
+                    $('#scalingTypeIn').removeAttr("checked");\r
+                }\r
+            });\r
         };\r
 \r
         //loadTableData();\r
@@ -449,7 +463,30 @@ var app = angular.module("lcApp", ["ui.router", "ngTable"])/*, 'ui.bootstrap', '
                 }\r
             };\r
             bootbox.confirm("Do you confirm to delete service?", deleteHandle);     \r
-        }\r
+        };\r
+\r
+        $scope.scaleData = function (id) {\r
+            var nsInstanceId = id;\r
+            $('#scaleNS').click(\r
+                function() {\r
+                    var scaleIn = $('#scalingTypeIn').attr('checked');\r
+                    var scaleType = scaleIn === undefined ? 'SCALE_OUT' : 'SCALE_IN';\r
+                    var aspectId = $('#scalingAspect').val();\r
+                    var numberOfSteps = $('#numberOfSteps').val();\r
+                    var resultHandleFun = function(response) {\r
+                        if (response.status === 'finished') {\r
+                            console.log('scale successfully!');\r
+                        } else {\r
+                            console.log('Scaling service failed! ' + response);\r
+                            //showErrorMessage('Scaling service failed',response);\r
+                        }\r
+                    };\r
+                    DataService.scaleService(nsInstanceId, scaleType, aspectId, numberOfSteps, resultHandleFun);\r
+                    $('#scaleNS').unbind('click');\r
+                }\r
+            );\r
+            $('#scaleOptionDialog').modal();\r
+        };\r
 \r
     })\r
 \r
index cac3f80..b5bcdd7 100644 (file)
@@ -44,6 +44,7 @@
                 <!--<img src="../images/delete.png" ng-click="editData(lcData.id)" style="cursor: pointer"></img>-->
                 <!--<span class="pull-right glyphicon glyphicon-edit" ng-click="editData(lcData.serviceId)" style="cursor: pointer;margin: 0 5px"></span>-->
                 <span class="pull-right glyphicon glyphicon-trash" ng-click="deleteIndividualData(lcData.serviceId)" style="cursor: pointer;margin: 0 5px"></span>
+                <span class="pull-right glyphicon glyphicon-circle-arrow-right" ng-click="scaleData(lcData.serviceId)" style="cursor: pointer;margin: 0 5px"></span>
             </td>
         </tr>
     </table>
         <div class="modal-content">
             <div class="modal-header">
                 <button type="button" class="close" data-dismiss="modal" 
-                        aria-hidden="true">¡Á
+                        aria-hidden="true">��
                 </button>
                 <h4 class="modal-title" id="errorDialogTitle"  style="text-align:center;"></h4>
             </div>
         </div>
     </div>
 </div>
+
+<!--scale option dialog-->
+<div id="scaleOptionDialog" class="modal fade" role="dialog">
+    <div class="modal-dialog">
+        <!-- Modal content-->
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal">&times;</button>
+                <h5 class="modal-title titlestyle">Scale Option</h5>
+            </div>
+            <div class="modal-body">
+                <div class="form-group row" style="height:26px;margin-top:15px; margin-left:25px;">
+                    <span class="col-xs-3" style="margin-left:20px">
+                        <input type="radio" id="scalingTypeIn"/>  Scale In
+                    </span>
+                    <span class="col-xs-offset-2 col-xs-3">
+                        <input type="radio" id="scalingTypeOut"/>  Scale Out
+                    </span>
+                </div>
+                <div class="form-group row" style="margin-left:25px;">
+                    <label class="col-xs-3 control-label">
+                        <span>Scaling Aspect</span>
+                        <span class="required">*</span>
+                    </label>
+                    <div class="col-xs-7">
+                        <input type="text" id="scalingAspect" name="scalingAspect" class="form-control" maxlength="256"/>
+                    </div>
+                </div>
+                <div class="form-group row" style="margin-left:25px;">
+                    <label class="col-xs-3 control-label">
+                        <span>Number of Steps</span>
+                        <span class="required">*</span>
+                    </label>
+                    <div class="col-xs-7">
+                        <input type="text" id="numberOfSteps" name="numberOfSteps" class="form-control"  maxlength="256"/>
+                    </div>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" style="width:80px;" class="btn SDBtn" data-dismiss="modal"
+                            aria-hidden="true" id="scaleNS">
+                        <span>OK</span>
+                    </button>
+                    <button type="button" style="width:80px;" class="btn button-previous SDBtn" data-dismiss="modal">
+                        <span>Cancel</span>
+                    </button>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<!--scale progress bar-->
+<div class="modal fade" id="scaleProgressDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <div class="modal-header" style="margin-left:10px;margin-bottom:5px;">
+                <h4 class="modal-title" id="idScaleProgressTitle" style="text-align:center;"></h4>
+            </div>
+            <div class="modal-body" style="margin-left:10px;margin-bottom:5px;margin-right:10px;">
+                <div class="progress">
+                    <div id="scaleProgressbar" class="progress-bar" role="progressbar" style="width: 10%;">
+                        <span id ="scaleProgressValue">0%</span>
+                    </div>
+                </div>
+                <div id="scaleProgressContent"></div>
+            </div>
+        </div>
+    </div>
+</div>