Esempio n. 1
0
    def __init__(self, feed_layer, *args, **kwargs):
        super().__init__(*args, **kwargs)

        uic.loadUi(os.path.join(os.path.dirname(__file__), "MainWindow.ui"),
                   self)

        jsonpickle.set_encoder_options('simplejson', sort_keys=True, indent=4)
        jsonpickle.set_encoder_options('json', sort_keys=True, indent=4)
        jsonpickle.set_preferred_backend("simplejson")

        self.__tabs = {}

        self.uiMainTabWidget = self.findChild(QTabWidget, "tabWidget")
        self.uiMainTabWidget.tabCloseRequested.connect(self.closeView)

        nodes = self.__loadConfigFromFile(MainWindow.FILENAME_CONFIG_NODES, {})
        self.nodes = NodeManager(nodes)

        views = self.__loadConfigFromFile(MainWindow.FILENAME_CONFIG_VIEWS, {})
        self.views = ViewManager(views)

        self.sensorManager = SensorManager(self.views.callbackUpdate,
                                           self.nodes.addId)

        nodeConfigTab = NodeConfigTab(
            self.nodes, callbackModified=self.callbackModifiedNodes)
        self.nodes.setCallbackNodeAdded(nodeConfigTab.add)
        self.uiMainTabWidget.addTab(nodeConfigTab, "Konfiguration")
        self.uiMainTabWidget.tabBar().setTabButton(0, QTabBar.RightSide, None)

        viewConfigTab = ViewConfigTab(
            self.views,
            self.nodes,
            self.showView,
            callbackModified=self.callbackModifiedViews)
        self.uiMainTabWidget.addTab(viewConfigTab, "Ansichten")
        self.uiMainTabWidget.tabBar().setTabButton(1, QTabBar.RightSide, None)

        self.__updateTimer = QtCore.QTimer(self)
        self.__updateTimer.setInterval(1000)
        self.__updateTimer.timeout.connect(self.views.updateWidgets)
        self.__updateTimer.start()

        if feed_layer is not None:
            self.link = feed_layer
            self.readAllEvents()
            self.link.subscribe_sensor_feed(self.parseSensorFeedEventNoId)
        else:
            self.link = None
            self.demoTimer = None
Esempio n. 2
0
    def __init__(self):
        logger_format = '%(asctime)-15s:: %(message)s'
        logging.basicConfig(format=logger_format,
                            filename="./logs/central_node")
        self._logger = logging.getLogger("CentralNode")
        self._node_mapping = NodeMap()
        self._node_manager = NodeManager()
        self._table = dict()
        self._table_lock = Lock()
        self._latency_map = LatencyMap()
        #dict to store test data
        self._time_data_final = dict()

        #shared queue for broadcasting packets
        # each queue entry should be a tuple
        # containing the next hop ip and data
        # (next_hop_ip, data)
        self._packet_queue = Queue.Queue(maxsize=0)
        for i in range(self._NUM_PROCESSING_THREADS):
            t = Thread(target=self._process_packet)
            t.setDaemon(True)
            t.start()

        t_server = Thread(target=self._central_node_server)
        t_server.setDaemon(True)
        t_server.start()
Esempio n. 3
0
    def __init__(self, root, goal, graphFile, heuristicFile):
        self.uid = 1
        rootName = str(0) + "_" + root + "_" + str(0)
        file = open("frontier/frontierFile", "w+")
        print rootName
        file.write(rootName + "\n")
        file.close()

        file2 = open("frontier/" + rootName, "w+")
        print "frontier/" + rootName
        file2.write(str(0) + "\n")
        file2.write(root)
        file2.close()

        self.goalFound = False
        self.goal = goal

        self.explore = False

        self.nodeManager = NodeManager()
        self.nodeManager.generateGraph(graphFile, heuristicFile)
Esempio n. 4
0
import Queue
from NodeManager import NodeManager
from multiprocessing import Process
if __name__ == '__main__':

    url_q = Queue.Queue()
    result_q = Queue.Queue()
    store_q = Queue.Queue()
    conn_q = Queue.Queue()

    node = NodeManager()
    manager = node.start_Manager(url_q, result_q)

    url_manager_proc = Process(
        target=node.url_manager_proc,
        args=(url_q, conn_q, 'http://baike.baidu.com/view/284853.html'))

    result_solve_proc = Process(target=node.result_solve_proc,
                                args=(result_q, conn_q, store_q))
    store_proc = Process(target=node.store_proc, args=(store_q, ))

    url_manager_proc.start()
    result_solve_proc.start()
    store_proc.start()
    manager.get_server().serve_forever()
    '''
  node.url_manager_proc(url_q,conn_q,'http://baike.baidu.com/view/284853.html')
  node.result_solve_proc(result_q,conn_q,store_q)
  node.store_proc(store_q)
  manager.get_server().serve_forever()
  '''
Esempio n. 5
0
from NodeManager import NodeManager

manager = NodeManager()
#manager.display_GUI()
#manager.collect_data()
Esempio n. 6
0
class MainWindow(QMainWindow):
    FILENAME_CONFIG_VIEWS = "views"
    FILENAME_CONFIG_NODES = "nodes"

    NODE_DEMO_ID = "2"

    def __init__(self, feed_layer, *args, **kwargs):
        super().__init__(*args, **kwargs)

        uic.loadUi(os.path.join(os.path.dirname(__file__), "MainWindow.ui"),
                   self)

        jsonpickle.set_encoder_options('simplejson', sort_keys=True, indent=4)
        jsonpickle.set_encoder_options('json', sort_keys=True, indent=4)
        jsonpickle.set_preferred_backend("simplejson")

        self.__tabs = {}

        self.uiMainTabWidget = self.findChild(QTabWidget, "tabWidget")
        self.uiMainTabWidget.tabCloseRequested.connect(self.closeView)

        nodes = self.__loadConfigFromFile(MainWindow.FILENAME_CONFIG_NODES, {})
        self.nodes = NodeManager(nodes)

        views = self.__loadConfigFromFile(MainWindow.FILENAME_CONFIG_VIEWS, {})
        self.views = ViewManager(views)

        self.sensorManager = SensorManager(self.views.callbackUpdate,
                                           self.nodes.addId)

        nodeConfigTab = NodeConfigTab(
            self.nodes, callbackModified=self.callbackModifiedNodes)
        self.nodes.setCallbackNodeAdded(nodeConfigTab.add)
        self.uiMainTabWidget.addTab(nodeConfigTab, "Konfiguration")
        self.uiMainTabWidget.tabBar().setTabButton(0, QTabBar.RightSide, None)

        viewConfigTab = ViewConfigTab(
            self.views,
            self.nodes,
            self.showView,
            callbackModified=self.callbackModifiedViews)
        self.uiMainTabWidget.addTab(viewConfigTab, "Ansichten")
        self.uiMainTabWidget.tabBar().setTabButton(1, QTabBar.RightSide, None)

        self.__updateTimer = QtCore.QTimer(self)
        self.__updateTimer.setInterval(1000)
        self.__updateTimer.timeout.connect(self.views.updateWidgets)
        self.__updateTimer.start()

        if feed_layer is not None:
            self.link = feed_layer
            self.readAllEvents()
            self.link.subscribe_sensor_feed(self.parseSensorFeedEventNoId)
        else:
            self.link = None
            self.demoTimer = None

    def readAllEvents(self):
        fid = self.link.get_sensor_feed_fid()
        eventCount = self.link.get_feed_length(fid)

        for seq in range(eventCount):
            self.parseSensorFeedEventNoId(self.link.get_event_content(
                fid, seq))

    def pushInterval(self, interval):
        fid = self.link.get_control_feed_fid()
        self.link.create_event(fid, f"{int(interval)}")

    def stopTimer(self):
        self.readTimer.cancel()

    def callbackModifiedNodes(self):
        if self.nodes.containsId(MainWindow.NODE_DEMO_ID):
            self.pushInterval(self.nodes.get(MainWindow.NODE_DEMO_ID).interval)
        self.__saveConfigToFile(self.nodes.getAll(),
                                MainWindow.FILENAME_CONFIG_NODES)

    def callbackModifiedViews(self):
        self.__saveConfigToFile(self.views.getAll(),
                                MainWindow.FILENAME_CONFIG_VIEWS)

    def addSensorDataSet(self, nodeId, timestamp, t, p, h, b):
        # T=1 P=2 rH=3 J=%
        # d/m/Y
        time = timestamp.timestamp()
        self.sensorManager.addData(nodeId, "T_celcius", float(t), time)
        self.sensorManager.addData(nodeId, "P_bar", float(p), time)
        self.sensorManager.addData(nodeId, "rH", float(h), time)
        self.sensorManager.addData(nodeId, "J_lumen", float(b), time)

    def parseSensorFeedEventNoId(self, feedEvent):
        print("DATA: {}".format(feedEvent))
        data = ast.literal_eval(feedEvent)
        if len(data) != 5:
            return
        self.addSensorDataSet(
            MainWindow.NODE_DEMO_ID,
            datetime.datetime.strptime(data[0], '%d/%m/%y %H:%M:%S'), data[1],
            data[2], data[3], data[4])

    def parseSensorFeedEvent(self, feedEvent):
        data = ast.literal_eval(feedEvent)
        if len(data) != 6:
            return
        self.addSensorDataSet(
            data[0], datetime.datetime.strptime(data[1], '%d/%m/%y %H:%M:%S'),
            data[2], data[3], data[4], data[5])

    def readSensorFeed(self):
        sensorFid = self.link.get_sensor_feed_fid()
        feedLength = self.link.get_feed_length(sensorFid)
        feedEvent = self.link.get_event_content(sensorFid, feedLength - 1)
        self.parseSensorFeedEvent(feedEvent)

    def periodicRead(self, interval):
        self.readSensorFeed()
        self.readTimer = threading.Timer(interval,
                                         self.periodicRead,
                                         args=[interval])
        self.readTimer.start()

    '''
        View Methods
    '''

    def showView(self, view):
        if view is None:
            return

        widget = self.views.open(view.id)

        for yAxis in view.getYAxes():
            if not yAxis.active:
                continue
            for nodeId, sensorId in yAxis.sensors.items():
                widget.setData(
                    yAxis.id, nodeId, sensorId,
                    self.sensorManager.dataReference(nodeId, sensorId))

        index = self.uiMainTabWidget.indexOf(widget)
        if index >= 0:
            self.uiMainTabWidget.setCurrentIndex(index)
        else:
            self.uiMainTabWidget.addTab(widget, view.name)
            self.uiMainTabWidget.setCurrentWidget(widget)
        widget.setOpen(True)

    def closeView(self, tabIndex):
        if tabIndex > 1:
            widget = self.uiMainTabWidget.widget(tabIndex)
            if isinstance(widget, ViewWidget):
                widget.setOpen(False)
            self.uiMainTabWidget.removeTab(tabIndex)

    '''
        General Methods
    '''

    def __saveConfigToFile(self, config, filename):
        if config is None or not isinstance(filename, str):
            return False
        with open(filename + ".json", "w") as f:
            f.write(jsonpickle.encode(config))

    def __loadConfigFromFile(self, filename, default=None):
        if not isinstance(filename,
                          str) or not os.path.isfile(filename + ".json"):
            return default
        with open(filename + ".json", "r") as f:
            config = jsonpickle.decode(f.read())

        return config

    def demo(self, interval):
        if interval < 1 or not self or not self.isVisible():
            print(self.isVisible())
            if self.demoTimer is not None:
                self.demoTimer.cancel()
            return
        self.parseSensorFeedEvent(
            f"['1','{datetime.datetime.now().strftime('%d/%m/%y %H:%M:%S')}','{random.random() * 3 + 20}','{random.randrange(10000) + 95000}','{random.random() * 30 + 30}','{random.random() * 10 + 50}']"
        )
        self.demoTimer = threading.Timer(interval, self.demo, args=[interval])
        self.demoTimer.start()

    def show(self):
        super().show()
        if self.link is None:
            self.demo(2)
import rospy

from Misc import bcolors
from LaunchManager import LaunchManager
from NodeManager import NodeManager
from NavManager import NavManager
from SpeechManager import SpeechManager
from math import pi
from geometry_msgs.msg import PoseWithCovarianceStamped

if __name__ == '__main__':
    cSpeechManager = SpeechManager()
    cLaunchManager = LaunchManager(10)
    cNodeManager = NodeManager()
    cNavManager = NavManager('/home/turtlebot/BJ/actual_waypoint_list.csv', 0)
    print(
        bcolors.OKBLUE +
        "======================All Classes Initialized========================"
        + bcolors.ENDC)
    print(
        bcolors.OKBLUE +
        "====================================================================="
        + bcolors.ENDC)
    if 1:
        print(
            bcolors.OKBLUE +
            "=======================Prepare Navigation========================================"
            + bcolors.ENDC)
        cLaunchManager.StartNavLaunchFile()
        cNodeManager.WaitForNavNodes()
        cNavManager.ManageNav()
Esempio n. 8
0
class FrontierManager():
    """docstring for FrontierFile"""
    def __init__(self, root, goal, graphFile, heuristicFile):
        self.uid = 1
        rootName = str(0) + "_" + root + "_" + str(0)
        file = open("frontier/frontierFile", "w+")
        print rootName
        file.write(rootName + "\n")
        file.close()

        file2 = open("frontier/" + rootName, "w+")
        print "frontier/" + rootName
        file2.write(str(0) + "\n")
        file2.write(root)
        file2.close()

        self.goalFound = False
        self.goal = goal

        self.explore = False

        self.nodeManager = NodeManager()
        self.nodeManager.generateGraph(graphFile, heuristicFile)

    def expandPath(self, line, child, pathCost, heuristicCost):
        print "\t######expand path######"
        file = open("frontier/" + line, "r")

        totalCost = int(file.next()) + int(pathCost)
        completeCost = totalCost + heuristicCost

        split = line.split("_")

        print "\tfrontier/" + str(completeCost) + "_" + child + "_" + str(
            self.uid), "w+"

        newFile = open(
            "frontier/" + str(completeCost) + "_" + child + "_" +
            str(self.uid), "w+")
        text = file.next()

        newFile.write(str(totalCost) + "\n")

        print "\tCost: " + str(totalCost)

        # Loop until EOF
        try:
            while True:
                print "\tPath: " + text
                newFile.write(text + "\n")
                text = text[:-1]
                text = file.next()
        except StopIteration as e:
            pass

        newFile.write(child + "\n")

        print "\tPath: " + child

        self.uid = self.uid + 1

        file.close()
        newFile.close()

        # Copy frontier and rename, ready to append new node to path
        #newPath = "frontier/" + str(self.cost + cost) + self.name + str(self.uid)
        #shutil.copyfile(self.name, newPath)

    # Adds children, returns the number of children added
    def addFrontierFile(self, node):
        if node == -1:
            return -1

        print "######addFrontierFile########"
        file = open("frontier/frontierFile", "r")
        line = file.next()
        line = line[:-1]
        updated = open("frontier/updated", "w+")

        childrenCount = 0

        try:
            # Loop until EOF
            while True:
                print "\tline " + repr(str(line))
                print "\tnode " + str(node)
                if line == node:
                    print "\tLine == node (found best in frontier file)"
                    split = line.split("_")
                    parent = self.nodeManager.getNode(split[1])

                    for child in parent.getConnections():
                        print "\tChild in parent.getConnections(): " + child

                        #if self.explore == True and parent == self.goal

                        if self.alreadyVisited(line, child):
                            print "\tContinued"
                            continue

                        # Get path cost so far
                        pathFile = open("frontier/" + line, "r")
                        actualNode = self.nodeManager.getNode(child)

                        #completeCost = int(file.next()) + pathCost + heuristicCost
                        completeCost = int(pathFile.next()) + int(
                            parent.getCost(child)) + int(actualNode.heuristic)
                        pathFile.close()

                        # Add file name to frontierFile
                        updated.write(
                            str(completeCost) + "_" + child + "_" +
                            str(self.uid) + "\n")
                        print "\tAppended to updated: " + str(
                            completeCost) + "_" + child + "_" + str(self.uid)

                        # Create frontier file
                        self.expandPath(
                            line, child, parent.getCost(child),
                            self.nodeManager.getNode(child).heuristic)

                        childrenCount = childrenCount + 1

                        print "\tGoal: " + self.goal + " - Child: " + repr(
                            child)
                        if self.goal == child:
                            self.goalFound = True

                    os.remove("frontier/" + line)
                    print "Removed: frontier/" + line
                else:
                    # Write line to new file
                    updated.write(line + "\n")

                line = file.next()
                print line
                #line = file.next()
                #print line + "dfg"
                line = line[:-1]
                #print line
        except StopIteration as e:
            print "ugh"

        file.close()
        updated.close()

        os.remove("frontier/frontierFile")
        shutil.copyfile("frontier/updated", "frontier/frontierFile")
        os.remove("frontier/updated")

        if self.goalFound:
            childrenCount = 0

            pathList = open("frontier/frontierFile", "r")
            path = pathList.next()

            try:
                while True:
                    self.printPaths(path[:-1])
                    path = pathList.next()
            except StopIteration as e:
                pass

            pathList.close()

        return childrenCount

    # USES 1 NODE
    def alreadyVisited(self, line, nodeName):
        # Loop until EOF
        file = open("frontier/" + line, "r")
        line = file.next()
        #print "alreadyVisited 1 " + line[:-1]
        line = file.next()
        #print "alreadyVisited 2 " + line

        try:
            while True:
                #print "Line: " + line
                #print "NodeName: " + nodeName
                if line[:-1] == nodeName:
                    file.close()
                    print "\t\t" + line + "ALREADY VISITED"
                    return True

                line = file.next()
        except StopIteration as e:
            pass

        file.close()

        print "\t\t" + line + " NOT VISITED"

        return False

    # USES 1 NODE first
    def findBestNode(self):
        print "#######Find best node######"
        file = open("frontier/frontierFile", "r+")

        line = ""

        try:
            line = file.next()
            #print "\tfrontierFile: " + line[:-1]
        except StopIteration as e:
            pass

        info = line.split("_")

        # Default the first value to best for comparison

        bestCost = info[0]
        bestName = info[1]
        bestID = info[2]

        bestOption = line

        try:
            # Loop until EOF
            while True:
                info = line.split("_")

                if info[0] == bestCost:
                    if info[1] < bestName:
                        bestCost = info[0]
                        bestName = info[1]
                        bestID = info[2]
                        bestOption = line
                elif info[0] < bestCost:
                    bestCost = info[0]
                    bestName = info[1]
                    bestID = info[2]
                    bestOption = line

                print "\tfrontierFile: " + line[:-1]
                line = file.next()
        except StopIteration as e:
            pass

        file.close()

        print "\tBest Option: " + bestOption[:-1]

        return bestOption[:-1]

    def printPaths(self, file):
        nodes = open("frontier/" + file, "r")
        line = nodes.next()
        line = nodes.next()
        string = ""
        try:
            while True:
                rep = repr(line[:-1])
                if rep != "''":
                    string = string + repr(line[:-1])

                line = nodes.next()

                if rep != "''":
                    string = string + " --> "
        except StopIteration as e:
            nodes.close()
            print string

    def findAlternatives(self, limit):
        self.goalFound = False
        self.removeGoals()
        print "Find Alternatives"
        file = open("frontier/frontierFile", "r+")

        line = ""

        try:
            line = file.next()
            print "1"
        except StopIteration as e:
            pass

        info = line.split("_")

        # Default the first value to best for comparison

        bestCost = info[0]
        bestName = info[1]
        bestID = info[2]

        bestOption = line

        try:
            # Loop until EOF
            while True:
                print "2"
                info = line.split("_")

                if info[0] == bestCost:
                    if info[1] < bestName:
                        bestCost = info[0]
                        bestName = info[1]
                        bestID = info[2]
                        bestOption = line
                elif info[0] < bestCost:
                    bestCost = info[0]
                    bestName = info[1]
                    bestID = info[2]
                    bestOption = line

                line = file.next()
        except StopIteration as e:
            pass

        file.close()

        if bestCost > limit:
            print "Nothing better can be found"
            return -1

        print "Best Option: " + bestOption[:-1]

        return bestOption[:-1]

    def removeGoals(self):
        pathList = open("frontier/frontierFile", "r")
        updated = open("frontier/updated", "w+")
        path = pathList.next()

        try:
            while True:
                info = path.split("_")
                if self.goal == info[1]:
                    os.remove("frontier/" + path[:-1])
                    print "Removed Goal: " + path
                else:
                    updated.write(path)

                path = pathList.next()
        except StopIteration as e:
            updated.close()
            pathList.close()

        os.remove("frontier/frontierFile")
        shutil.copyfile("frontier/updated", "frontier/frontierFile")
        os.remove("frontier/updated")
Esempio n. 9
0
def run_test():
    node = {
        "host": "k8s-nminion-05",
        "ipaddr": "172.19.136.203",
        "system_info": {
            "os": "ubuntu-14.04",
            "account": "ubuntu",
            "pubkey":
            "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkyjBMFzm2TViVZlgK6AS1bONpsVH7iG5ngksVZmWdA0p50koCkRxkVaECVa+exB6rb7jxCOt6Qskw0uDO3pyOiPEk21rJJHRsQqmdTG3erD+DuWNwnxtXuGmK9AJzMoE1bwb9qaMfePdqMYK42WaV+kk9X1wflNuPK40No4PrMd0fzRErnaoHoAbUfcpV3JkUEgiboH6Pd2y4Cozm9vi+Mg2bmrcBY7C7Qd59zZJHZDyTBcw04dZ7otkZk37X2Ghg8M4dYQ77OXed/C2vMeojlno7mCf0T18Wdn14/5ug9JvlTqgj7Qo8lxxPBNvPu+pwivPJVnZbE5CmRZV5gybz [email protected]",
            "pemkey": "/Users/junerson/dev/.keys/kubernetes.pem"
        },
        "role": ["node"],
        "component_info": {
            "kubelet": "v1.5.2",
            "kube-proxy": "v1.5.2",
            "flanneld": "0.5.5",
            "docker": "1.12.3"
        },
        "cluster": "cluster-5c15f70a",
        "cpu": 16,
        "mem": 24,
        "disk": 100,
        "tags": {
            "test": "test1"
        },
        "status": "False"
    }

    node_info = {"uuid": "node-20456ca1"}

    # transfer a json
    #node_info_json = json.dumps(node)
    #serializer = NodeSerializer(data=node)
    node = Node.objects.get(uuid=node_info['uuid'])
    print(node)
    serializer = NodeSerializer(node)

    #if serializer.is_valid():
    #print("validated data : %s" % serializer.validated_data)
    #print(serializer.validated_data)
    #print(serializer.data)
    node_manager = NodeManager(serializer.data)
    cluster_obj = node.cluster
    component_obj = Component.objects.all().filter(
        cluster=str(node.cluster.uuid))
    registries = [str(x) for x in cluster_obj.platform_info['registry']]
    res = node_manager.initNode()

    if not res:
        print("ERROR) initNode()")
        sys.exit(1)

    res = node_manager.installDocker(registries)

    if not res:
        print("ERROR) installDocker()")

    res = node_manager.launchBox(cluster_obj, component_obj)
    time.sleep(4)
    node_manager.startNode()
    time.sleep(1)
    node_manager.reConfDocker(registries)
Esempio n. 10
0
        print("[+] Request Finishes")
        



LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(filename = 'node.log',level = logging.DEBUG,format = LOG_FORMAT)
logger = logging.getLogger()

for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
    signal.signal(sig, handler) 

name = os.environ['USER']
interface = ni.interfaces()[1]
ipv4_addr =  ni.ifaddresses(interface)[AF_INET][0]['addr']
manager = NodeManager(name)
manager.start()




HOST, PORT = '', 9998
server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)
server.allow_reuse_address = True
print("[+] Start listening")
server.serve_forever()