<commit_before>


function SubServiceControl($scope, $routeParams, $location, $interval, resourcesService, authService) {
    // Ensure logged in
    authService.checkLogin($scope);
    $scope.name = "servicedetails";
    $scope.params = $routeParams;
    $scope.servicesService = resourcesService;

    $scope.defaultHostAlias = location.hostname;
    var re = /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/
    if (re.test(location.hostname) || location.hostname == "localhost") {
        $.getJSON("/hosts/defaultHostAlias", "", function(data) {
            $scope.defaultHostAlias = data.hostalias;
        });
    }

    $scope.breadcrumbs = [
        { label: 'breadcrumb_deployed', url: '#/apps' }
    ];

    $scope.services = buildTable('Name', [
        { id: 'Name', name: 'deployed_tbl_name'},
        { id: 'DesiredState', name: 'deployed_tbl_state' },
        { id: 'Health', name: 'Health' },
        { id: 'Startup', name: 'label_service_startup' }
    ]);

    $scope.vhosts = buildTable('vhost_name', [
        { id: 'Name', name: 'vhost_name'},
        { id: 'Application', name: 'vhost_application'},
        { id: 'ServiceEndpoint', name: 'vhost_service_endpoint'},
        { id: 'URL', name: 'vhost_url'},
        { id: 'Action', name: 'vhost_actions'},
    ]);

    $scope.ips = buildTable('Service', [
        { id: 'Service', name: 'tbl_virtual_ip_service'},
        { id: 'Application', name: 'tbl_virtual_ip_application'},
        { id: 'AssignmentType', name: 'tbl_virtual_ip_assignment_type'},
        { id: 'Host', name: 'tbl_virtual_ip_host'},
        { id: 'Pool', name: 'tbl_virtual_ip_pool'},
        { id: 'IPAddress', name: 'tbl_virtual_ip'},
        { id: 'Port', name: 'tbl_virtual_ip_port'},
        { id: 'Actions', name: 'tbl_virtual_ip_actions'}
    ]);

    //add vhost data (includes name, app & service endpoint)
    $scope.vhosts.add = {};

    //app & service endpoint option for adding a new virtual host
    $scope.vhosts.options = [];

    $scope.click_app = function(id) {
        $location.path('/services/' + id);
    };

    $scope.click_pool = function(id) {
        $location.path('/pools/' + id);
    };

    $scope.click_host = function(id) {
        $location.path('/hosts/' + id);
    };

    $scope.modalAddVHost = function() {
        $('#addVHost').modal('show');
    };

    $scope.addVHost = function() {
        if (!$scope.vhosts.add.name || $scope.vhosts.add.name.length <= 0) {
            console.error( "Cannot add vhost -- missing name");
            return;
        }

        if ($scope.vhosts.options.length <= 0) {
            console.error( "Cannot add vhost -- no available application and service");
            return;
        }

        var name = $scope.vhosts.add.name;
        var serviceId = $scope.vhosts.add.app_ep.ServiceID;
        var serviceEndpoint = $scope.vhosts.add.app_ep.ServiceEndpoint;
        resourcesService.add_vhost( serviceId, serviceEndpoint, name, function() {
            $scope.vhosts.add = {};
            refreshServices($scope, resourcesService, false);
        });
    };

    // modalAssignIP opens a modal view to assign an ip address to a service
    $scope.modalAssignIP = function(ip, poolID) {
      $scope.ips.assign = {'ip':ip, 'value':null}
      resourcesService.get_pool_ips(poolID, function(data) {
        var options= [{'Value':'Automatic', 'IPAddr':null}]

        //host ips
        for(var i = 0; i < data.HostIPs.length; ++i) {
          var IPAddr = data.HostIPs[i].IPAddress
          var value = 'Host: ' + IPAddr + ' - ' + data.HostIPs[i].InterfaceName
          options.push({'Value': value, 'IPAddr':IPAddr})
          // set the default value to the currently assigned value
          if ($scope.ips.assign.ip.IPAddr == IPAddr) {
            $scope.ips.assign.value = options[ options.length-1]
          }
        }
        for(var i = 0; i < data.VirtualIPs.length; ++i) {
          var IPAddr = data.VirtualIPs[i].IP
          var value =  "Virtual IP: " + IPAddr
          options.push({'Value': value, 'IPAddr':IPAddr})
          // set the default value to the currently assigned value
          if ($scope.ips.assign.ip.IPAddr == IPAddr) {
            $scope.ips.assign.value = options[ options.length-1]
          }
        }

        //default to automatic
        if(!$scope.ips.assign.value) {
          $scope.ips.assign.value = options[0]
        }

        $scope.ips.assign.options = options
        $('#assignIP').modal('show');
      })
    };

    $scope.AssignIP = function() {<commit_msg>guard for null virtualIps and hostIps<commit_after>


function SubServiceControl($scope, $routeParams, $location, $interval, resourcesService, authService) {
    // Ensure logged in
    authService.checkLogin($scope);
    $scope.name = "servicedetails";
    $scope.params = $routeParams;
    $scope.servicesService = resourcesService;

    $scope.defaultHostAlias = location.hostname;
    var re = /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/
    if (re.test(location.hostname) || location.hostname == "localhost") {
        $.getJSON("/hosts/defaultHostAlias", "", function(data) {
            $scope.defaultHostAlias = data.hostalias;
        });
    }

    $scope.breadcrumbs = [
        { label: 'breadcrumb_deployed', url: '#/apps' }
    ];

    $scope.services = buildTable('Name', [
        { id: 'Name', name: 'deployed_tbl_name'},
        { id: 'DesiredState', name: 'deployed_tbl_state' },
        { id: 'Health', name: 'Health' },
        { id: 'Startup', name: 'label_service_startup' }
    ]);

    $scope.vhosts = buildTable('vhost_name', [
        { id: 'Name', name: 'vhost_name'},
        { id: 'Application', name: 'vhost_application'},
        { id: 'ServiceEndpoint', name: 'vhost_service_endpoint'},
        { id: 'URL', name: 'vhost_url'},
        { id: 'Action', name: 'vhost_actions'},
    ]);

    $scope.ips = buildTable('Service', [
        { id: 'Service', name: 'tbl_virtual_ip_service'},
        { id: 'Application', name: 'tbl_virtual_ip_application'},
        { id: 'AssignmentType', name: 'tbl_virtual_ip_assignment_type'},
        { id: 'Host', name: 'tbl_virtual_ip_host'},
        { id: 'Pool', name: 'tbl_virtual_ip_pool'},
        { id: 'IPAddress', name: 'tbl_virtual_ip'},
        { id: 'Port', name: 'tbl_virtual_ip_port'},
        { id: 'Actions', name: 'tbl_virtual_ip_actions'}
    ]);

    //add vhost data (includes name, app & service endpoint)
    $scope.vhosts.add = {};

    //app & service endpoint option for adding a new virtual host
    $scope.vhosts.options = [];

    $scope.click_app = function(id) {
        $location.path('/services/' + id);
    };

    $scope.click_pool = function(id) {
        $location.path('/pools/' + id);
    };

    $scope.click_host = function(id) {
        $location.path('/hosts/' + id);
    };

    $scope.modalAddVHost = function() {
        $('#addVHost').modal('show');
    };

    $scope.addVHost = function() {
        if (!$scope.vhosts.add.name || $scope.vhosts.add.name.length <= 0) {
            console.error( "Cannot add vhost -- missing name");
            return;
        }

        if ($scope.vhosts.options.length <= 0) {
            console.error( "Cannot add vhost -- no available application and service");
            return;
        }

        var name = $scope.vhosts.add.name;
        var serviceId = $scope.vhosts.add.app_ep.ServiceID;
        var serviceEndpoint = $scope.vhosts.add.app_ep.ServiceEndpoint;
        resourcesService.add_vhost( serviceId, serviceEndpoint, name, function() {
            $scope.vhosts.add = {};
            refreshServices($scope, resourcesService, false);
        });
    };

    // modalAssignIP opens a modal view to assign an ip address to a service
    $scope.modalAssignIP = function(ip, poolID) {
      $scope.ips.assign = {'ip':ip, 'value':null}
      resourcesService.get_pool_ips(poolID, function(data) {
        var options= [{'Value':'Automatic', 'IPAddr':null}]

        //host ips
        if ( data && data.HostIPs) {
          for(var i = 0; i < data.HostIPs.length; ++i) {
            var IPAddr = data.HostIPs[i].IPAddress
            var value = 'Host: ' + IPAddr + ' - ' + data.HostIPs[i].InterfaceName
            options.push({'Value': value, 'IPAddr':IPAddr})
            // set the default value to the currently assigned value
            if ($scope.ips.assign.ip.IPAddr == IPAddr) {
              $scope.ips.assign.value = options[ options.length-1]
            }
          }
        }

        //host ips
        if ( data && data.VirtualIPs) {
          for(var i = 0; i < data.VirtualIPs.length; ++i) {
            var IPAddr = data.VirtualIPs[i].IP
            var value =  "Virtual IP: " + IPAddr
            options.push({'Value': value, 'IPAddr':IPAddr})
            // set the default value to the currently assigned value
            if ($scope.ips.assign.ip.IPAddr == IPAddr) {
              $scope.ips.assign.value = options[ options.length-1]
            }
          }
        }

        //default to automatic
        if(!$scope.ips.assign.value) {
          $scope.ips.assign.value = options[0]
        }

        $scope.ips.assign.options = options
        $('#assignIP').modal('show');
      })
    };

    $scope.AssignIP = function() {
{'fraction_non_alphanumeric': 0.1710678590215676, 'fraction_numerical': 0.01409784324039979, 'mean_word_length': 2.384122463510146, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4884109', 'n_tokens_mistral': 3171, 'n_tokens_neox': 3092, 'n_words': 599}