Example #1
0
    def components(self, instanceName=None, verbose=False, try_count=5):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path
        comps = []
        if verbose:
            sys.stdout.write('## get components from nameserver(%s)\n' % self.path)

        def func(node, comps, instanceName=instanceName):
            if instanceName:
                if node.instanceName == instanceName:
                    comps.append(node)
            else:
                comps.append(node)

        def filter_func(node):
            if node.is_component and not node.parent.is_manager:
                return True
            return False

        for i in range(0, try_count):
            try:
                if not self.tree:
                    self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                    self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                    self.dir_node = self.tree.get_node(self.__path)

                self.dir_node.iterate(func, comps, [filter_func])
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting component information from nameserver(%s)\n' % self.path)
                if verbose:
                    traceback.print_exc()
                self.tree = None
                pass
            time.sleep(0.5)
Example #2
0
 def refresh(self, verbose=False, force=False, try_count=5):
     from rtctree import path as rtctree_path
     from rtctree import tree as rtctree_tree
     import omniORB
     for i in range(0, try_count):
         try:
             #if self.tree and force:
             #    del(self.tree)
             #    del(self.dir_node)
             #    self.tree = None
             if self.tree:
                 orb = self.tree.orb
                 self.tree.give_away_orb()
             else:
                 orb = None
             if not self.tree or force:
                 sys.stdout.write('# Refreshing tree... for %s\n' % self.path)
                 self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                 self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path], orb=orb)
                 self.dir_node = self.tree.get_node(self.__path)
                 sys.stdout.write('## Success.\n')
                 return 
         except omniORB.CORBA.OBJECT_NOT_EXIST, e:
             print 'omniORB.CORBA.OBJECT_NOT_EXIST'
         except omniORB.OBJECT_NOT_EXIST_NoMatch, e:
             print 'omniORB.OBJECT_NOT_EXIST_NoMatch'
Example #3
0
 def task_func(args):
     try:
         if verbose: sys.stdout.write('#### Checking RTCTree.....\n')
         ns.tree = rtctree_tree.RTCTree(paths=path, filter=[path])
         if verbose: sys.stdout.write('#### Done.\n')
     except:
         if verbose: sys.stdout.write('#### Exception.\n')
         pass
Example #4
0
 def rtcs(self, try_count=5):
     from rtctree import path as rtctree_path
     from rtctree import tree as rtctree_tree
     for i in range(0, try_count):
         try:
             if not self.tree:
                 self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                 self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                 self.dir_node = self.tree.get_node(self.__path)
             break
         except Exception, e:
             pass
Example #5
0
    def dataports(self, data_type="any", port_type=['DataInPort', 'DataOutPort'], try_count=5, polarity="any", verbose=False):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path
        ports = []
        if verbose:
            sys.stdout.write('## get dataports from nameserver(%s)\n' % self.path)

        def func(node, ports, data_type=data_type, port_type=port_type):
            ports__ = []
            if 'DataInPort' in port_type:
                ports__ = ports__ + node.inports
            if 'DataOutPort' in port_type:
                ports__ = ports__ + node.outports
            if data_type == 'any':
                for port in ports__:
                    ports.append(port)
            else:
                for port in ports__:
                    if port.properties['dataport.data_type'] == data_type:
                        ports.append(port)
                #for port in [port for port in ports__ if port.properties['dataport.data_type'] == data_type]:
                #    ports.append(port)

        def filter_func(node):
            if node.is_component and not node.parent.is_manager:
                return True
            return False

        for i in range(0, try_count):
            try:
                if not self.tree:
                    self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                    self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                    self.dir_node = self.tree.get_node(self.__path)

                self.dir_node.iterate(func, ports, [filter_func])
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting dataport information from nameserver(%s)\n' % self.path)
                if verbose:
                    traceback.print_exc()
                self.tree = None
                pass
            time.sleep(0.5)
Example #6
0
    def svcports(self, interface_type="any", try_count=5, polarity="any"):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path

        ports = []
        def func(node, ports, interface_type=interface_type, polarity=polarity):
            for port in node.svcports:
                for intf in port.interfaces:
                    if interface_type != 'any':
                        if not intf.type_name == interface_type:
                            continue
                        pass
                    if polarity != 'any':
                        if not intf.polarity_as_string(False) == polarity:
                            continue
                    ports.append(port)

        def filter_func(node):
            if node.is_component and not node.parent.is_manager:
                return True
            return False


        for i in range(0, try_count):
            try:
                if not self.tree:
                    if verbose: sys.stdout.write('## Refreshing Name Server Tree.\n')
                    self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                    self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                    self.dir_node = self.tree.get_node(self.__path)
                self.dir_node.iterate(func, ports, [filter_func])
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting service port information from nameserver(%s)\n' % self.path)
                if verbose:
                    traceback.print_exc()
                pass
            time.sleep(0.5)
Example #7
0
    def component(self, path, func, verbose=False, try_count=5):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path
        comps = []
        if verbose:
            sys.stdout.write('## get components from nameserver(%s)\n' % path)

        for i in range(0, try_count):
            try:
                path_, port_ = rtctree_path.parse_path('/' + path)
                tree = rtctree_tree.RTCTree(paths=path_, filter=[path_])
                dir_node = tree.get_node(path_)
                if dir_node.is_component:
                    if func:
                        func(dir_node)
                    return dir_node
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting component information from nameserver(%s)\n' % path)
                if verbose:
                    traceback.print_exc()
                self.tree = None
                pass
            time.sleep(0.5)
Example #8
0
    def yaml_dump(self, long=False, detail=False, verbose=False):
        from rtctree import tree as rtctree_tree
        from rtctree import path as rtctree_path
        ports = []
        tab = '  '
        ns_only = True

        def show_func(node, tablevel, long=False, detail=False):

            if node.is_nameserver:
                full_path  = node.full_path[1]
                if full_path.startswith('/'): full_path = full_path[1:]
                sys.stdout.write(tab * tablevel + '"' + full_path + '":' + '\n')
            elif node.is_manager:
                sys.stdout.write(tab * tablevel + '' + node.name + ': {}\n')                
            elif node.is_directory:
                sys.stdout.write(tab * tablevel + '' + node.name + ':\n')
            elif node.is_zombie:
                sys.stdout.write(tab * tablevel + '' + node.name + '* : {}\n')                
            elif node.is_component:
                if not long and not detail:
                    sys.stdout.write(tab * tablevel + '' + node.name + '\n')
                else:
                    sys.stdout.write(tab * tablevel + '' + node.name + ':\n')
                    sys.stdout.write(tab * (tablevel + 1) + 'DataOutPorts:\n')
                    if len(node.outports) == 0:
                        sys.stdout.write(tab * (tablevel + 2) + '{}\n')
                    else:
                        for p in node.outports:
                            self._print_port(p, long, detail, 4)

                    sys.stdout.write(tab * (tablevel + 1) + 'DataInPorts:\n')
                    if len(node.inports) == 0:
                        sys.stdout.write(tab * (tablevel + 2) + '{}\n')
                    else:
                        for p in node.inports:
                            self._print_port(p, long, detail, 4)
                    sys.stdout.write(tab * (tablevel + 1) + 'ServicePorts:\n')
                    if len(node.svcports) == 0:
                        sys.stdout.write(tab * (tablevel + 2) + '{}\n')
                    else:
                        for p in node.svcports:
                            self._print_port(p, long, detail, 4)
                    sys.stdout.write(tab * (tablevel + 1) + 'ConfigurationSets:\n')
                    if len(node.conf_sets) == 0:
                        sys.stdout.write(tab * (tablevel + 2) + '{}\n')
                    else:
                        for cs in node.conf_sets:
                            self._print_conf_set(cs, node.conf_sets[cs], long, detail, 3+1)

                    sys.stdout.write(tab * (tablevel + 1) + 'properties:\n')
                    for key in sorted(node.properties.keys()):
                        value = node.properties[key]
                        sys.stdout.write(tab * (tablevel + 2) + key + ' : "' + value + '"\n')
                    sys.stdout.write(tab * (tablevel + 1) + 'state : ' + node.get_state_string(add_colour=False) + '\n')
                    sys.stdout.write(tab * (tablevel + 1) + 'exec_cxts:\n')
                    ec = node.get_ec(0)
                    for ec1 in node.owned_ecs:
                        #sys.stdout.write(tab * (tablevel + 2) + 'owner : ' + str(ec.participants) + '\n')
                        #sys.stdout.write(tab * (tablevel + 2) + 'state : ' + str(ec.get_component_state(node)) + '\n')
                        sys.stdout.write(tab * (tablevel + 2) + 'properties:\n')
                        for key in sorted(ec.properties.keys()):
                            value = ec.properties[key]
                            sys.stdout.write(tab * (tablevel + 3) + key + ' : "' + value + '"\n')

            if not node.is_manager:
                for c in node.children:
                    show_func(c, tablevel+1, long, detail)
                if not node.is_component and not node.is_zombie:
                    if len(node.children) == 0:
                        sys.stdout.write(tab * tablevel + tab  + '{}\n');
            
        try_count = 5
        import omniORB
        for i in range(0, try_count):
            try:
                if not self.tree:
                    if verbose: sys.stdout.write('## Refreshing Name Server Tree.\n')
                    self.__path, self.__port = rtctree_path.parse_path('/' + self.path)
                    self.tree = rtctree_tree.RTCTree(paths=self.__path, filter=[self.__path])
                    self.dir_node = self.tree.get_node(self.__path)
                sys.stdout.write('"' + self.path + '":\n')
                for c in self.dir_node.children:
                    show_func(c, 1, long, detail)
                if len(self.dir_node.children) == 0:
                    sys.stdout.write('  {}\n')
                
                break
            except Exception, e:
                sys.stdout.write('## Exception occurred when getting tree information from nameserver(%s)\n' % self.path)
                if verbose:
                    traceback.print_exc()
                pass
            except omniORB.CORBA.OBJECT_NOT_EXIST_NoMatch, e:
                sys.stdout.write('## CORBA.OBJECT_NOT_EXIST\n')