Beispiel #1
0
def zookeeper_health_check_get_app():
    labels = {
        '_client_conn_port': 31001,
        '_follower_conn_port': 31002,
        '_server_conn_port': 31003
    }

    app1 = MarathonApp(id='/new-zookeeper/zookeeper-1',
                       labels=labels,
                       tasks=[MarathonTask(host='127.0.0.1')],
                       tasks_unhealthy=0,
                       tasks_running=1,
                       mem=256,
                       cpus=0.5,
                       disk=256)
    app2 = MarathonApp(id='/new-zookeeper/zookeeper-2',
                       labels=labels,
                       tasks=[MarathonTask(host='127.0.0.2')],
                       tasks_unhealthy=0,
                       tasks_running=1,
                       mem=256,
                       cpus=0.5,
                       disk=256)
    app3 = MarathonApp(id='/new-zookeeper/zookeeper-3',
                       labels=labels,
                       tasks=[MarathonTask(host='127.0.0.3')],
                       tasks_unhealthy=0,
                       tasks_running=1,
                       mem=256,
                       cpus=0.5,
                       disk=256)
    return [app1, app2, app3]
Beispiel #2
0
    def test_do_not_call_task_method_if_filter_does_not_implement(self):
        """
        Caso um filtro não implemente write_task, apenas não chamamos esse filtro
        durante o pipeline
        """
        class DummyFilter:
            def write(self, user, request_app, original_app):
                raise Exception()

        pipeline = {
                OperationType.WRITE: [DummyFilter(), ]
        }

        request_data = {"ids": ["task_0"]}
        request_app = MarathonTask.from_json({'id': request_data['ids'][0]})
        original_app = request_app # Por enquanto não temos como passar a original task

        with application.test_request_context("/v2/tasks/delete",
                                              method="POST",
                                              data=json.dumps(request_data),
                                              headers={"Content-type": "application/json"}) as ctx:
            ctx.request.user = self.user
            request = Request(ctx.request)
            with patch.object(request, "split", return_value=[(request_app, original_app)]):
                filtered_request = dispatch(self.user, request, filters_pipeline=pipeline)
                filtered_app = MarathonTask.from_json({"id": filtered_request.get_json()['ids'][0]})
                self.assertEqual("task_0", filtered_app.id)
    def test_call_write_task_if_is_v2_tasks_request(self):
        """
        Se o request é em PUT /v2/tasks o pipeline deve chamar write_task()
        """
        class DummyFilter:
            def write_task(self, user, request_task, orignal_tasK):
                request_task.id = request_task.id + "_suffix"
                return request_task

            def write(self, user, request_app, original_app):
                raise Exception()

        class DummyFilter2:
            """
            Esse filtro existe por causa de uma regressão,
            onde o método do filtro era chamado mais de uma vez, quando
            o filtro seguinte não implementa o mesmo método do filtro anterior.
            Nesse caso o método do filtro anterior era chamado novamente.
            """
            pass

        pipeline = {
            OperationType.WRITE: [
                DummyFilter(),
                DummyFilter2(),
            ]
        }

        request_data = {"ids": ["task_0"]}
        request_app = MarathonTask.from_json({'id': request_data['ids'][0]})
        original_app = request_app  # Por enquanto não temos como passar a original task

        with application.test_request_context(
                "/v2/tasks/delete",
                method="POST",
                data=json.dumps(request_data),
                headers={"Content-type": "application/json"}) as ctx:
            ctx.request.user = self.user
            request = Request(ctx.request)
            with patch.object(request,
                              "split",
                              return_value=[(request_app, original_app)]):
                filtered_request = dispatch(self.user,
                                            request,
                                            filters_pipeline=pipeline)
                filtered_app = MarathonTask.from_json(
                    {"id": filtered_request.get_json()['ids'][0]})
                self.assertEqual("task_0_suffix", filtered_app.id)
Beispiel #4
0
def redis_health_check_get_app():
    app1 = MarathonApp(id='/sandbox/redis-master',
                       tasks=[MarathonTask(host='127.0.0.1')],
                       tasks_unhealthy=0,
                       tasks_running=1,
                       mem=256,
                       cpus=0.5,
                       disk=256)

    app2 = MarathonApp(
        id='/sandbox/redis-slave',
        tasks=[MarathonTask(host='127.0.0.1')],
        cmd=
        'docker-entrypoint.sh redis-server --port $REDIS_PORT --slaveof 127.0.0.1 $REDIS_PORT',
        tasks_running=1,
        mem=256,
        cpus=0.5,
        disk=256)
    return [app1, app2]
Beispiel #5
0
def list_service_instances(client):
    """ Lists existing instances for app 'sleepy'

        Arguments: MarathonClient object

        Returns: JSON array of existing instances
    """

    # Returns a list of MarathonTask objects

    task_list = client.list_tasks('sleepy') 

    # Builds list convertng MarathonTask objects into JSON

    instances = [MarathonTask.to_json(x) for x in task_list]
    return '['+','.join(instances)+']'  # Builds valid JSON output
Beispiel #6
0
def spark_health_check_get_app():
    port_mappings = [
        MarathonContainerPortMapping(service_port=10001),
        MarathonContainerPortMapping(service_port=10002),
        MarathonContainerPortMapping(service_port=10003),
        MarathonContainerPortMapping(service_port=10004)
    ]
    docker = MarathonDockerContainer(image='node', port_mappings=port_mappings)
    container = MarathonContainer(docker=docker)
    labels = {'_tonomi_environment': 'sandbox', '_tonomi_application': 'spark'}
    app1 = MarathonApp(id='/sandbox/spark/spark-app',
                       labels=labels,
                       cpus=0.5,
                       mem=256,
                       disk=256,
                       instances=1,
                       container=container,
                       tasks=[MarathonTask(host='127.0.0.1')])
    app1.tasks_unhealthy = 0
    app1.tasks_running = 1
    return [app1]
Beispiel #7
0
def redis_launch_get_app():
    app1 = MarathonApp(id='/sandbox/redis-master',
                       tasks=[MarathonTask(host='127.0.0.0')])
    return [app1]
Beispiel #8
0
def cassandra_launch_get_app():
    app1 = MarathonApp(id='/new-cassandra',
                       tasks=[MarathonTask(host='127.0.0.1')])
    return [app1]
Beispiel #9
0
def webui_launch_get_app():
    app1 = MarathonApp(id='/sandbox/cassandra-seed',
                       tasks=[MarathonTask(host='127.0.0.1')],
                       labels={'_cql_native_port': '31942'})
    return [app1]
Beispiel #10
0
def list_service_instances(client):

    task_list = client.list_tasks('sleepy')
    instances = [MarathonTask.to_json(x) for x in task_list]
    return ','.join(instances)