Exemplo n.º 1
0
    def test_hung_processes(self):
        ps_output = [{
            'id': 58002,
            'type': 'core'
        }, {
            'id': 58003,
            'type': 'agent'
        }]

        stdout = MagicMock()
        stderr = MagicMock()
        mock_os_kill = MagicMock()
        mock_time_sleep = MagicMock()
        mock_find_pids = MagicMock(return_value=ps_output)

        with patch('os.kill', mock_os_kill), \
                patch('time.sleep', mock_time_sleep), \
                patch('conductr_cli.sandbox_common.find_pids', mock_find_pids):
            logging_setup.configure_logging(MagicMock(**self.default_args),
                                            stdout, stderr)
            sandbox_stop_jvm.stop(MagicMock(**self.default_args))

        self.assertEqual(
            headline('Stopping ConductR') + '\n', self.output(stdout))
        self.assertEqual(
            strip_margin(
                as_error(
                    """|Error: ConductR core pid 58002 could not be stopped
                                                  |Error: ConductR agent pid 58003 could not be stopped
                                                  |Error: Please stop the processes manually
                                                  |""")), self.output(stderr))
        mock_os_kill.assert_has_calls(
            [call(58002, signal.SIGTERM),
             call(58003, signal.SIGTERM)])
Exemplo n.º 2
0
 def start(self):
     if major_version(self.image_version) == 1:
         pass
     else:
         log = logging.getLogger(__name__)
         log.info(
             headline(
                 'Starting logging feature based on elasticsearch and kibana'
             ))
         log.info(
             'conductr-kibana bundle is packaged as a Docker image. Checking Docker requirements..'
         )
         docker.validate_docker_vm(docker.vm_type())
         log.info('Docker is installed and configured correctly.')
         elasticsearch = select_bintray_uri('conductr-elasticsearch',
                                            self.version_args)
         log.info('Deploying bundle %s..' % elasticsearch['bundle'])
         elasticsearch_load_command = ['load', elasticsearch['bundle'], '--disable-instructions'] + \
             parse_offline_mode_arg(self.offline_mode)
         conduct_main.run(elasticsearch_load_command,
                          configure_logging=False)
         conduct_main.run(
             ['run', elasticsearch['name'], '--disable-instructions'],
             configure_logging=False)
         kibana = select_bintray_uri('conductr-kibana', self.version_args)
         log.info('Deploying bundle %s..' % kibana['bundle'])
         kibana_load_command = ['load', kibana['bundle'], '--disable-instructions'] + \
             parse_offline_mode_arg(self.offline_mode)
         conduct_main.run(kibana_load_command, configure_logging=False)
         conduct_main.run([
             'run', kibana['name'], '--disable-instructions',
             '--wait-timeout', '600'
         ],
                          configure_logging=False)
Exemplo n.º 3
0
def stop(args):
    """
    Stops the existing ConductR core and agent processes.
    This is done by interrogating the output of the ps, looking for java process which is running of the sandbox image.
    directory.

    :param args: args parsed from the input arguments
    """
    log = logging.getLogger(__name__)
    core_info, agent_info = sandbox_common.resolve_conductr_info(
        args.image_dir)

    pids_info = sandbox_common.find_pids(core_info['extraction_dir'],
                                         agent_info['extraction_dir'])
    if pids_info:
        log.info(headline('Stopping ConductR'))
        killed_pids_info, hung_pids_info = kill_processes(
            core_info, agent_info, pids_info)
        if hung_pids_info:
            for hung_pid_info in hung_pids_info:
                log.error('ConductR {} pid {} could not be stopped'.format(
                    hung_pid_info['type'], hung_pid_info['id']))
            log.error('Please stop the processes manually')
            return False
        else:
            log.info('ConductR has been successfully stopped')
            return True
    else:
        return True
Exemplo n.º 4
0
def start_proxy(nr_of_containers):
    log = logging.getLogger(__name__)
    bundle_name = 'conductr-haproxy'
    configuration_name = 'conductr-haproxy-dev-mode'
    log.info(headline('Starting HAProxy'))
    log.info('Deploying bundle {} with configuration {}'.format(bundle_name, configuration_name))
    conduct_main.run(['load', bundle_name, configuration_name, '--disable-instructions'], configure_logging=False)
    conduct_main.run(['run', bundle_name, '--scale', str(nr_of_containers), '--disable-instructions'], configure_logging=False)
Exemplo n.º 5
0
def stop(args):
    """`sandbox stop` command"""

    log = logging.getLogger(__name__)
    running_containers = sandbox_common.resolve_running_docker_containers()
    if running_containers:
        log.info(headline('Stopping ConductR'))
        terminal.docker_rm(running_containers)
Exemplo n.º 6
0
 def start(self):
     if major_version(self.image_version) == 1:
         pass
     else:
         log = logging.getLogger(__name__)
         log.info(headline('Starting logging feature based on eslite'))
         eslite = select_bintray_uri('eslite', self.version_args)
         log.info('Deploying bundle %s..' % eslite['bundle'])
         conduct_main.run(['load', eslite['bundle'], '--disable-instructions'], configure_logging=False)
         conduct_main.run(['run', eslite['name'], '--disable-instructions'], configure_logging=False)
Exemplo n.º 7
0
 def start(self):
     if major_version(self.image_version) == 1:
         pass
     else:
         log = logging.getLogger(__name__)
         log.info(headline('Starting visualization feature'))
         visualizer = select_bintray_uri('visualizer', self.version_args)
         log.info('Deploying bundle %s..' % visualizer['bundle'])
         conduct_main.run(['load', visualizer['bundle'], '--disable-instructions'], configure_logging=False)
         conduct_main.run(['run', visualizer['name'], '--disable-instructions'], configure_logging=False)
Exemplo n.º 8
0
def print_result(container_names, is_started, no_wait, wait_timeout, image_version):
    if not no_wait:
        log = logging.getLogger(__name__)
        if is_started:
            log.info(headline('Summary'))
            log.info('ConductR has been started')
            plural_string = 's' if len(container_names) > 1 else ''
            log.info('Check resource consumption of Docker container{} that run the ConductR node{} with:'
                     .format(plural_string, plural_string))
            log.info('  docker stats {}'.format(' '.join(container_names)))
            log.info('Check current bundle status with:')
            log.info('  conduct info')
            if major_version(image_version) != 1:
                log.info('Bundle status:')
                conduct_main.run(['info'], configure_logging=False)
        else:
            log.info(headline('Summary'))
            log.error('ConductR has not been started within {} seconds.'.format(wait_timeout))
            log.error('Set the env CONDUCTR_SANDBOX_WAIT_RETRY_INTERVAL to increase the wait timeout.')
Exemplo n.º 9
0
 def start(self):
     log = logging.getLogger(__name__)
     log.info(headline('Starting monitoring feature'))
     bundle_repo = ''
     if self.version_args and self.version_args[0] == 'snapshot':
         bundle_repo = 'lightbend/commercial-monitoring/'
     grafana = select_bintray_uri('cinnamon-grafana', self.version_args, bundle_repo)
     log.info('Deploying bundle %s..' % grafana['bundle'])
     conduct_main.run(['load', grafana['bundle'], '--disable-instructions'], configure_logging=False)
     conduct_main.run(['run', grafana['name'], '--disable-instructions'], configure_logging=False)
Exemplo n.º 10
0
    def test_success(self):
        stdout = MagicMock()
        containers = ['cond-0', 'cond-1']

        with patch('conductr_cli.sandbox_common.resolve_running_docker_containers', return_value=containers), \
                patch('conductr_cli.terminal.docker_rm') as mock_docker_rm:
            logging_setup.configure_logging(MagicMock(**self.default_args), stdout)
            sandbox_stop.stop(MagicMock(**self.default_args))

        self.assertEqual(headline('Stopping ConductR') + '\n', self.output(stdout))
        mock_docker_rm.assert_called_once_with(containers)
Exemplo n.º 11
0
def log_run_attempt(args, run_result, is_started, wait_timeout):
    container_names = run_result.container_names
    if not args.no_wait:
        log = logging.getLogger(__name__)
        if is_started:
            log.info(headline('Summary'))
            log.info('ConductR has been started')
            plural_string = 's' if len(container_names) > 1 else ''
            log.info(
                'Check resource consumption of Docker container{} that run the ConductR node{} with:'
                .format(plural_string, plural_string))
            log.info('  docker stats {}'.format(' '.join(container_names)))
            log.info('Check current bundle status with:')
            log.info('  conduct info')
        else:
            log.info(headline('Summary'))
            log.error(
                'ConductR has not been started within {} seconds.'.format(
                    wait_timeout))
            log.error(
                'Set the env CONDUCTR_SANDBOX_WAIT_RETRY_INTERVAL to increase the wait timeout.'
            )
Exemplo n.º 12
0
 def start(self):
     if major_version(self.image_version) == 1:
         pass
     else:
         log = logging.getLogger(__name__)
         log.info(headline('Starting logging feature based on eslite'))
         eslite = select_bintray_uri('eslite', self.version_args)
         log.info('Deploying bundle %s..' % eslite['bundle'])
         load_command = ['load', eslite['bundle'], '--disable-instructions'] + \
             parse_offline_mode_arg(self.offline_mode)
         conduct_main.run(load_command, configure_logging=False)
         conduct_main.run(['run', eslite['name'], '--disable-instructions'],
                          configure_logging=False)
Exemplo n.º 13
0
def log_run_attempt(args, run_result, is_started, wait_timeout):
    """
    Logs the run attempt. This method will be called after the completion of run method and when all the features has
    been started.

    :param args: args parsed from the input arguments
    :param run_result: the result from calling sandbox_run_jvm.run() - instance of sandbox_run_jvm.SandboxRunResult
    :param is_started: sets to true if sandbox is started
    :param wait_timeout: the amount of timeout waiting for sandbox to be started
    :return:
    """
    log = logging.getLogger(__name__)
    if not args.no_wait:
        if is_started:
            log.info(headline('Summary'))
            log.info('ConductR has been started:')

            nr_instance_core = len(run_result.core_pids)
            plural_core = 's' if nr_instance_core > 1 else ''
            log.info('  core: {} instance{}'.format(nr_instance_core,
                                                    plural_core))

            nr_instance_agent = len(run_result.agent_pids)
            plural_agents = 's' if nr_instance_agent > 1 else ''
            log.info('  agent: {} instance{}'.format(nr_instance_agent,
                                                     plural_agents))

            log.info('Check current bundle status with:')
            log.info('  conduct info')
            conduct_main.run(['info', '--host', run_result.host],
                             configure_logging=False)
        else:
            log.info(headline('Summary'))
            log.error(
                'ConductR has not been started within {} seconds.'.format(
                    wait_timeout))
            log.error(
                'Set the env CONDUCTR_SANDBOX_WAIT_RETRY_INTERVAL to increase the wait timeout.'
            )
Exemplo n.º 14
0
 def start(self):
     if major_version(self.image_version) == 1:
         pass
     else:
         log = logging.getLogger(__name__)
         log.info(headline('Starting logging feature based on elasticsearch and kibana'))
         elasticsearch = select_bintray_uri('conductr-elasticsearch', self.version_args)
         log.info('Deploying bundle %s..' % elasticsearch['bundle'])
         conduct_main.run(['load', elasticsearch['bundle'], '--disable-instructions'], configure_logging=False)
         conduct_main.run(['run', elasticsearch['name'], '--disable-instructions'], configure_logging=False)
         kibana = select_bintray_uri('conductr-kibana', self.version_args)
         log.info('Deploying bundle %s..' % kibana['bundle'])
         conduct_main.run(['load', kibana['bundle'], '--disable-instructions'], configure_logging=False)
         conduct_main.run(['run', kibana['name'], '--disable-instructions'], configure_logging=False)
Exemplo n.º 15
0
def stop_proxy():
    log = logging.getLogger(__name__)

    try:
        running_container = get_running_haproxy()
        if running_container:
            log.info(headline('Stopping HAProxy'))
            is_docker_present()
            terminal.docker_rm([DEFAULT_SANDBOX_PROXY_CONTAINER_NAME])
            log.info('HAProxy has been successfully stopped')

        return True
    except (AttributeError, CalledProcessError):
        # Fail silently as these errors will be raised if Docker is not installed or Docker environment is not
        # configured properly.
        return False
Exemplo n.º 16
0
def stop(args):
    log = logging.getLogger(__name__)
    running_containers = sandbox_common.resolve_running_docker_containers()
    if running_containers:
        log.info(headline('Stopping ConductR'))
        try:
            terminal.docker_rm(running_containers)
            log.info('ConductR has been successfully stopped')
            return True
        except (AttributeError, CalledProcessError):
            log.error(
                'ConductR containers could not be stopped pid 58002 could not be stopped'
            )
            log.error('Please stop the Docker containers manually')
            return False
    else:
        return True
Exemplo n.º 17
0
 def start(self):
     log = logging.getLogger(__name__)
     log.info(headline('Starting monitoring feature'))
     bundle_repo = 'lightbend/commercial-monitoring/' if self.version_args and self.version_args[0] == 'snapshot' \
         else ''
     bundle_name = 'cinnamon-grafana' if major_version(
         self.image_version) == 1 else 'cinnamon-grafana-docker'
     grafana = select_bintray_uri(bundle_name, self.version_args,
                                  bundle_repo)
     log.info('Deploying bundle %s..' % grafana['bundle'])
     load_command = ['load', grafana['bundle'], '--disable-instructions'] + \
         parse_offline_mode_arg(self.offline_mode)
     conduct_main.run(load_command, configure_logging=False)
     conduct_main.run([
         'run', grafana['name'], '--disable-instructions', '--wait-timeout',
         '600'
     ],
                      configure_logging=False)
Exemplo n.º 18
0
def run(args, features):
    """
    Starts the ConductR core and agent.

    :param args: args parsed from the input arguments
    :param features: list of features which are specified via -f switch.
                     This is only relevant for Docker based sandbox since the features decides what port to expose
    :return: SandboxRunResult
    """
    nr_of_core_instances, nr_of_agent_instances = instance_count(
        args.image_version, args.nr_of_instances)

    validate_jvm_support()

    validate_64bit_support()

    sandbox_stop.stop(args)

    log = logging.getLogger(__name__)
    log.info(headline('Starting ConductR'))

    bind_addrs = find_bind_addrs(
        max(nr_of_core_instances, nr_of_agent_instances), args.addr_range)

    core_extracted_dir, agent_extracted_dir = obtain_sandbox_image(
        args.image_dir, args.image_version, args.offline_mode)

    core_addrs = bind_addrs[0:nr_of_core_instances]
    core_pids = start_core_instances(core_extracted_dir, core_addrs,
                                     args.conductr_roles, features,
                                     args.log_level)

    agent_addrs = bind_addrs[0:nr_of_agent_instances]
    agent_pids = start_agent_instances(agent_extracted_dir,
                                       bind_addrs[0:nr_of_agent_instances],
                                       core_addrs, args.conductr_roles,
                                       features, args.log_level)

    return SandboxRunResult(core_pids, core_addrs, agent_pids, agent_addrs)
Exemplo n.º 19
0
def start_nodes(args, features):
    container_names = []
    log = logging.getLogger(__name__)
    log.info(headline('Starting ConductR'))
    ports = collect_ports(args, features)
    conductr_args = flatten([feature.conductr_args() for feature in features])
    conductr_features = flatten([feature.conductr_feature_envs() for feature in features])
    feature_conductr_roles = flatten([feature.conductr_roles() for feature in features])
    for i in range(args.nr_of_containers):
        container_name = '{prefix}{nr}'.format(prefix=CONDUCTR_NAME_PREFIX, nr=i)
        container_names.append(container_name)
        # Display the ports on the command line. Only if the user specifies a certain feature, then
        # the corresponding port will be displayed when running 'sandbox run' or 'sandbox debug'
        if ports:
            host_ip = host.resolve_ip_by_vm_type(args.vm_type)
            ports_desc = ' exposing ' + ', '.join(['{}:{}'.format(host_ip, map_port(i, port))
                                                   for port in sorted(ports)])
        else:
            ports_desc = ''
        log.info('Starting container {container}{port_desc}..'.format(container=container_name,
                                                                      port_desc=ports_desc))
        cond0_ip = inspect_cond0_ip() if i > 0 else None
        conductr_container_roles = resolve_conductr_roles_by_container(args.conductr_roles, feature_conductr_roles, i)
        run_conductr_cmd(
            i,
            args.nr_of_containers,
            container_name,
            cond0_ip,
            args.envs,
            '{image}:{version}'.format(image=args.image, version=args.image_version),
            args.log_level,
            ports,
            args.bundle_http_port,
            conductr_features,
            conductr_container_roles,
            conductr_args
        )
    return container_names
Exemplo n.º 20
0
def start_docker_instance(proxy_bind_addr, proxy_ports):
    log = logging.getLogger(__name__)
    log.info(headline('Starting HAProxy'))

    docker_image = terminal.docker_images(HAPROXY_DOCKER_IMAGE)
    if not docker_image:
        log.info('Pulling docker image {}'.format(HAPROXY_DOCKER_IMAGE))
        terminal.docker_pull(HAPROXY_DOCKER_IMAGE)

    all_proxy_ports = []
    all_proxy_ports.extend(DEFAULT_PROXY_PORTS)
    all_proxy_ports.extend(proxy_ports)
    all_proxy_ports = sorted(all_proxy_ports)

    port_args = []
    for port in all_proxy_ports:
        port_args.append('-p')
        port_args.append('{}:{}:{}'.format(proxy_bind_addr.exploded, port, port))

    docker_args = ['-d', '--name', DEFAULT_SANDBOX_PROXY_CONTAINER_NAME] + port_args + \
                  ['-v', '{}:/usr/local/etc/haproxy:ro'.format(HAPROXY_CFG_DIR)]

    log.info('Exposing the following ports {}'.format(all_proxy_ports))
    terminal.docker_run(docker_args, HAPROXY_DOCKER_IMAGE, positional_args=[])
Exemplo n.º 21
0
def start_nodes(args, nr_of_containers, features):
    container_names = []
    log = logging.getLogger(__name__)
    log.info(headline('Starting ConductR'))
    ports = collect_ports(args, features)
    conductr_args = flatten([feature.conductr_args() for feature in features])
    conductr_features = flatten(
        [feature.conductr_feature_envs() for feature in features])
    feature_conductr_roles = flatten(
        [feature.conductr_roles() for feature in features])
    for i in range(nr_of_containers):
        container_name = '{prefix}{nr}'.format(prefix=CONDUCTR_NAME_PREFIX,
                                               nr=i)
        container_names.append(container_name)
        # Display the ports on the command line. Only if the user specifies a certain feature, then
        # the corresponding port will be displayed when running 'sandbox run' or 'sandbox debug'
        if ports:
            host_ip = host.DOCKER_IP
            ports_desc = ' exposing ' + ', '.join([
                '{}:{}'.format(host_ip, map_port(i, port))
                for port in sorted(ports)
            ])
        else:
            ports_desc = ''
        log.info('Starting container {container}{port_desc}..'.format(
            container=container_name, port_desc=ports_desc))
        cond0_ip = inspect_cond0_ip() if i > 0 else None
        conductr_container_roles = sandbox_common.resolve_conductr_roles_by_instance(
            args.conductr_roles, feature_conductr_roles, i)
        run_conductr_cmd(
            i, nr_of_containers, container_name, cond0_ip, args.envs,
            '{image}:{version}'.format(image=args.image,
                                       version=args.image_version),
            args.log_level, ports, args.bundle_http_port, conductr_features,
            conductr_container_roles, conductr_args)
    return container_names