def post(self, container_id_or_name):
        self.set_header('Access-Control-Allow-Origin', '*')

        try:
            ar_container_manager = ARContainerManager()
            result = ar_container_manager.restart(container_id_or_name)
            self.write(result)
        except Exception as e:
            self.set_status(202)
            raise e
Exemplo n.º 2
0
    def get(self):
        self.set_header('Access-Control-Allow-Origin', '*')

        try:
            ar_container_manager = ARContainerManager()
            results = ar_container_manager.list()
            import json
            self.write(json.dumps(results))
        except Exception as e:
            self.set_status(202)
            raise e
Exemplo n.º 3
0
    def stats(self, service_name):
        status = ARContainerManager().status(self._container)['status']
        current_service_info = self.status(service_name)

        if status == ARContainerStatus.code(ARContainerStatus.RUNNING):
            pid = current_service_info['pid']
            service_status = current_service_info['status']
            if service_status == ARServiceStatus.code(ARServiceStatus.RUNNING):
                cpu_mem_percent = ARServiceManager.get_service_cpu_mem_percent(
                    self._container, pid)

                return {
                    'pid': pid,
                    'name': service_name,
                    'cpu_percent': cpu_mem_percent[0],
                    'mem_percent': cpu_mem_percent[1],
                    'container': self._container
                }

        return {
            'pid': current_service_info['pid'],
            'name': service_name,
            'cpu_percent': 0.0,
            'mem_percent': 0.0,
            'container': self._container
        }
Exemplo n.º 4
0
    def stop(self, service_name):
        status = ARContainerManager().status(self._container)['status']
        current_service_info = self.status(service_name)
        service_status = current_service_info['status']

        if status == ARContainerStatus.code(ARContainerStatus.RUNNING):
            if service_status in [
                    ARServiceStatus.code(ARServiceStatus.RUNNING),
                    ARServiceStatus.code(ARServiceStatus.STARTING)
            ]:
                self._server.supervisor.stopProcess(service_name)
            elif service_status in [
                    ARServiceStatus.code(ARServiceStatus.STOPPED),
                    ARServiceStatus.code(ARServiceStatus.EXITED)
            ]:
                pass
            elif service_status == ARServiceStatus.code(ARServiceStatus.FATAL):
                raise ARServiceException(
                    ServiceStatusPool.ID_SERVICE_STATUS_IN_FATAL)

        service_current_status = self.status(service_name)['status']
        service_stats = self.stats(service_name)

        return {
            'pid': current_service_info['pid'],
            'name': service_name,
            'status': service_current_status,
            'cpu_percent': service_stats['cpu_percent'],
            'mem_percent': service_stats['mem_percent'],
            'container': self._container
        }
Exemplo n.º 5
0
 def execute(command, service=None, container=None):
     if command == 'list':
         if container is not None and service is None:
             container = ARContainerManager.get_container_name(container)
             print ARServiceManager(container).list()
         else:
             print ARContainerManager().list()
     elif command == 'status':
         if container is not None and service is None:
             print ARContainerManager().status(container)
         elif container is not None and service is not None:
             print ARServiceManager(container).status(service)
     elif command == 'start':
         if container is not None and service is None:
             print ARContainerManager().start(container)
         elif container is not None and service is not None:
             print ARServiceManager(container).start(service)
     elif command == 'stop':
         if container is not None and service is None:
             print ARContainerManager().stop(container)
         elif container is not None and service is not None:
             print ARServiceManager(container).stop(service)
     elif command == 'restart':
         if container is not None and service is None:
             print ARContainerManager().restart(container)
         elif container is not None and service is not None:
             print ARServiceManager(container).restart(service)
     elif command == 'stats':
         if container is not None and service is None:
             print ARContainerManager().stats(container)
         elif container is not None and service is not None:
             print ARServiceManager(container).stats(service)
     elif command == 'version':
         print ARVersionManager().get_all_version()
Exemplo n.º 6
0
    def get(self):
        self.set_header('Access-Control-Allow-Origin', '*')

        try:
            container = ARContainerManager.get_container_name(self.
                                                              get_argument_value('container'))
            containers_names = ARContainerManager.get_all_containers_names()

            if container in containers_names:
                ar_service_manager = ARServiceManager(container)
                results = ar_service_manager.list()
                import json
                self.write(json.dumps(results))
            else:
                raise ARContainerException(ContainerStatusPool.ID_CONTAINER_DOES_NOT_EXIST)
        except Exception as e:
            self.set_status(202)
            raise e
Exemplo n.º 7
0
    def all():
        containers_names = ARContainerManager.get_all_containers_names()
        all_services = []

        for container in containers_names:
            for service in ARServiceManager(container).list():
                all_services.append(service)

        return all_services
Exemplo n.º 8
0
    def status(self, service_name):
        status = ARContainerManager().status(self._container)['status']
        if status == ARContainerStatus.code(ARContainerStatus.RUNNING):
            process_info = self._server.supervisor.getProcessInfo(service_name)
            return {
                'pid': process_info['pid'],
                'name': process_info['name'],
                'status': ARServiceStatus.code(process_info['statename']),
                'container': self._container
            }

        return {
            'pid': -1,
            'name': service_name,
            'status': ARServiceStatus.code(ARServiceStatus.EXITED),
            'container': self._container
        }
Exemplo n.º 9
0
    def list(self):
        results = []
        status = ARContainerManager().status(self._container)['status']
        services = CONTAINER_CONFIG[self._container]['services']

        if status == ARContainerStatus.code(ARContainerStatus.RUNNING):
            for service in services:
                service_info = self._server.supervisor.getProcessInfo(service)
                service_stats = self.stats(service)
                results.append({
                    'pid':
                    service_info['pid'],
                    'name':
                    service_info['name'],
                    'cpu_percent':
                    service_stats['cpu_percent'],
                    'mem_percent':
                    service_stats['mem_percent'],
                    'status':
                    ARServiceStatus.code(service_info['statename']),
                    'container':
                    self._container
                })

            return results

        for service in services:
            results.append({
                'pid':
                -1,
                'name':
                service,
                'cpu_percent':
                0.0,
                'mem_percent':
                0.0,
                'status':
                ARServiceStatus.code(ARServiceStatus.EXITED),
                'container':
                self._container
            })

        return results
Exemplo n.º 10
0
    def validate_container_and_service(*args):
        args_num = len(args)
        if args_num == 1:
            container = args[0]
            if container in CONTAINERS_NAMES or (CONTAINERS_IDS and container
                                                 in CONTAINERS_IDS):
                return True
        elif args_num == 2:
            container = args[0]
            service = args[1]
            if container in CONTAINERS_NAMES:
                if service in CONTAINER_CONFIG[container]['services']:
                    return True
            elif CONTAINERS_IDS and container in CONTAINERS_IDS:
                container_name = ARContainerManager.get_container_name(
                    container)
                if service in CONTAINER_CONFIG[container_name]['services']:
                    return True

        return False
Exemplo n.º 11
0
 def get_all_containers_ids():
     return ARContainerManager.get_all_containers_ids()