Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
add lisence, unify quotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mzmssg committed Jun 14, 2019
1 parent d120c76 commit ff05e4a
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 62 deletions.
17 changes: 17 additions & 0 deletions src/tools/config/logging.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

version: 1
disable_existing_loggers: False
formatters:
Expand Down
31 changes: 24 additions & 7 deletions src/tools/node_maintain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import print_function

import argparse
Expand Down Expand Up @@ -27,7 +44,7 @@ def get_unready_nodes(decommissioned_nodes, current_status):


def validate_string_is_ip(validated_str):
ip_pattern = re.compile(r'^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])(\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)){3}$')
ip_pattern = re.compile(r"^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])(\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)){3}$")
found = ip_pattern.match(validated_str) is not None
return found

Expand Down Expand Up @@ -100,7 +117,7 @@ def refresh_yarn_nodes(args):
unready_nodes = get_unready_nodes(decommissioned_nodes, current_status)
if len(unready_nodes) == 0:
break
unready_info = ','.join([node_name+' in '+status for node_name, status in unready_nodes.items()])
unready_info = ','.join([node_name+" in "+status for node_name, status in unready_nodes.items()])
logger.info("Unready nodes: {}. Waiting...".format(unready_info))
time.sleep(30)
logger.info("Successfully refresh nodes.")
Expand Down Expand Up @@ -353,15 +370,15 @@ def setup_parser():
parser_get.set_defaults(func=get_decommission_nodes)

parser_add = blacklist_subparsers.add_parser("add", parents=[parent_parser], help="add nodes to blacklist")
parser_add.add_argument("-n", "--nodes", type=convert_nodes, help='support comma-delimited node list', required=True)
parser_add.add_argument("-n", "--nodes", type=convert_nodes, help="support comma-delimited node list", required=True)
parser_add.set_defaults(func=add_decommission_nodes)

parser_remove = blacklist_subparsers.add_parser("remove", parents=[parent_parser], help="remove nodes from blacklist")
parser_remove.add_argument("-n", "--nodes", type=convert_nodes, help='support comma-delimited node list', required=True)
parser_remove.add_argument("-n", "--nodes", type=convert_nodes, help="support comma-delimited node list", required=True)
parser_remove.set_defaults(func=remove_decommission_nodes)

parser_update = blacklist_subparsers.add_parser("update", parents=[parent_parser], help="update blacklist")
parser_update.add_argument("-n", "--nodes", type=convert_nodes, help='support comma-delimited node list')
parser_update.add_argument("-n", "--nodes", type=convert_nodes, help="support comma-delimited node list")
parser_update.set_defaults(func=update_decommission_nodes)

parser_refresh = blacklist_subparsers.add_parser("enforce", parents=[parent_parser],
Expand All @@ -376,13 +393,13 @@ def setup_parser():
parser_get.set_defaults(func=get_dedicate_vc)

parser_add = dedicated_vc_subparsers.add_parser("add", parents=[parent_parser], help="add dedicate vc")
parser_add.add_argument("-n", "--nodes", type=convert_nodes, help='support comma-delimited node list', default={})
parser_add.add_argument("-n", "--nodes", type=convert_nodes, help="support comma-delimited node list", default={})
parser_add.add_argument("-v", "--vc-name", type=validate_vc_name, required=True)
parser_add.set_defaults(func=add_dedicate_vc)

parser_remove = dedicated_vc_subparsers.add_parser("remove", parents=[parent_parser], help="remove dedicate vc")
parser_remove.add_argument("-v", "--vc-name", type=validate_vc_name, required=True)
parser_remove.add_argument("-n", "--nodes", type=convert_nodes, help='support comma-delimited node list')
parser_remove.add_argument("-n", "--nodes", type=convert_nodes, help="support comma-delimited node list")
parser_remove.set_defaults(func=remove_dedicate_vc)

return top_parser
Expand Down
19 changes: 18 additions & 1 deletion src/tools/operator_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import absolute_import

__all__ = ['AlertOperator', 'KubernetesOperator', 'YarnOperator', 'Resource']
__all__ = ["AlertOperator", "KubernetesOperator", "YarnOperator", "Resource"]


from .alert_operator import AlertOperator
Expand Down
17 changes: 17 additions & 0 deletions src/tools/operator_wrapper/alert_operator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import logging
import sys

Expand Down
21 changes: 19 additions & 2 deletions src/tools/operator_wrapper/base_operator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import logging
import requests
import subprocess
Expand All @@ -12,7 +29,7 @@ def __init__(self, master_ip, port):

def request(self, api_path, method="get", return_json=True, timeout=10, **kwargs):

url = 'http://{}:{}{}'.format(self.master_ip, self.port, api_path)
url = "http://{}:{}{}".format(self.master_ip, self.port, api_path)

logger.debug("{}: {}".format(method, url))
func = getattr(requests, method)
Expand All @@ -34,6 +51,6 @@ def execute(self, command, redirect_stderr=True, shell=True, **kwargs):
return output


if __name__ == '__main__':
if __name__ == "__main__":
pass

17 changes: 17 additions & 0 deletions src/tools/operator_wrapper/kubernetes_operator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import sys
sys.path.append("../..")
from deployment.paiLibrary.common.kubernetes_handler import get_configmap, update_configmap
Expand Down
17 changes: 17 additions & 0 deletions src/tools/operator_wrapper/yarn_operator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import logging
import sys
import os
Expand Down
16 changes: 16 additions & 0 deletions src/tools/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 17 additions & 1 deletion src/tools/tests/test_alert_operator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import absolute_import

from mock import patch
Expand Down
28 changes: 22 additions & 6 deletions src/tools/tests/test_kubernetes_operator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import absolute_import

from mock import patch
Expand All @@ -10,15 +26,15 @@
class KubernetesOperatorTestCase(unittest.TestCase):

def setUp(self):
with patch('operator_wrapper.kubernetes_operator.KubernetesOperator.setup_kubernetes_configfile'):
with patch("operator_wrapper.kubernetes_operator.KubernetesOperator.setup_kubernetes_configfile"):
self.kubernetesOperator = KubernetesOperator("localhost")

@patch('operator_wrapper.kubernetes_operator.KubernetesOperator.setup_kubernetes_configfile')
@patch("operator_wrapper.kubernetes_operator.KubernetesOperator.setup_kubernetes_configfile")
def test__init__(self, setup_kubernetes_configfile):
KubernetesOperator("127.0.0.1")
setup_kubernetes_configfile.assert_called_with("127.0.0.1")

@patch('operator_wrapper.kubernetes_operator.common')
@patch("operator_wrapper.kubernetes_operator.common")
def test_setup_kubernetes_configfile(self, common_mock):
common_mock.read_template.return_value = "test"
common_mock.generate_from_template_dict.return_value = "test2"
Expand All @@ -32,7 +48,7 @@ def test_setup_kubernetes_configfile(self, common_mock):
common_mock.generate_from_template_dict.assert_called_with("test", dict_map)
common_mock.write_generated_file.assert_called_with("test2", self.kubernetesOperator.kube_config_path)

@patch('operator_wrapper.kubernetes_operator.get_configmap')
@patch("operator_wrapper.kubernetes_operator.get_configmap")
def test_get_nodes(self, get_configmap_mock):
get_configmap_mock.return_value = {
"data": {self.kubernetesOperator.configmap_data_key: "10.0.0.1\n10.0.0.2"}
Expand All @@ -42,7 +58,7 @@ def test_get_nodes(self, get_configmap_mock):

self.assertSetEqual(nodes, {"10.0.0.1", "10.0.0.2"})

@patch('operator_wrapper.kubernetes_operator.update_configmap')
@patch("operator_wrapper.kubernetes_operator.update_configmap")
def test_set_nodes(self, update_configmap_mock):
nodes = {"10.0.0.3", "10.0.0.4"}
nodes_str = "\n".join(nodes)
Expand Down
Loading

0 comments on commit ff05e4a

Please sign in to comment.