예제 #1
0
 def testBroadCastTask(self):
     "Send the task simultaneously to multiple devices. The task must be added before to the device"
     taskName = "task_one"
     maxSize = 3
     parameterDict = {"param1": 5, "param2": 1}
     model = None
     hardwareRequirements = {}
     configFile = None
     task = SpecificDeviceTask( taskName
                              , parameterDict
                              , model
                              , hardwareRequirements
                              , "test" #filename
                              , "test" #function
                              , configFile
                              )
     deviceHolder = DeviceHolder(maxSize)
     taskName = task.taskName 
     parameterDict = task.parameterDict
     deviceHolder.addDevice(self.deviceOne, taskName, parameterDict)
     deviceHolder.addDevice(self.deviceTwo, taskName, parameterDict)
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceOne.name
                                     , self.deviceOne.ipAdress
                                     , self.deviceOne.port 
                                     , self.deviceOne.hardwareConfig
                                     , self.deviceOne.initTask
                                     )
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceTwo.name
                                     , self.deviceTwo.ipAdress
                                     , self.deviceTwo.port 
                                     , self.deviceTwo.hardwareConfig
                                     , self.deviceTwo.initTask
                                     )
     deviceHolder.broadcastTask(task)
예제 #2
0
 def testChangefromOpentoFinishedTask(self):
     "Check if a finished task is removed from the openTaskDict"
     taskName = "task_one"
     parameterDict = {"param1": 5, "param2": 3}
     model = None
     hardwareRequirements = {}
     configFile = None
     task = SpecificDeviceTask(
         taskName,
         parameterDict,
         model,
         hardwareRequirements,
         "test"  #filename
         ,
         "test"  #function
         ,
         configFile)
     self.dartRuntime.generate_and_add_SingleDevice(
         self.deviceSingle.name, self.deviceSingle.ipAdress,
         self.deviceSingle.port, self.deviceSingle.hardwareConfig,
         self.deviceSingle.initTask)
     self.deviceSingle.addTask(task.taskName, task.parameterDict)
     self.deviceSingle.startTask(task)
     self.deviceSingle.get_taskResult(taskName)
     self.assertEqual(self.deviceSingle.openTaskDict, {},
                      msg="No open task!")
예제 #3
0
 def testStartTask(self):
     "Check starting a task. A task must be added before we can start the task"
     taskName = "task_one"
     parameterDict = {"param1": 5, "param2": 3}
     model = None
     hardwareRequirements = {}
     configFile = None
     task = SpecificDeviceTask(
         taskName,
         parameterDict,
         model,
         hardwareRequirements,
         "test"  #filename
         ,
         "test"  #function
         ,
         configFile)
     self.dartRuntime.generate_and_add_SingleDevice(
         self.deviceSingle.name, self.deviceSingle.ipAdress,
         self.deviceSingle.port, self.deviceSingle.hardwareConfig,
         self.deviceSingle.initTask)
     self.deviceSingle.addTask(task.taskName, task.parameterDict)
     self.deviceSingle.startTask(task)
     taskName = "task_two"
     task_two = SpecificDeviceTask(
         taskName,
         parameterDict,
         model,
         hardwareRequirements,
         "test"  #filename
         ,
         "test"  #function
         ,
         configFile)
     with self.assertRaises(Exception) as context:
         self.deviceSingle.startTask(task_two)
     self.assertTrue("Add the task" in str(context.exception))
예제 #4
0
 def testGetFinishedTasks(self):
     "Get the results from already finished devices"
     taskName = "task_one"
     maxSize = 3
     parameterDict = {"param1": 5, "param2": 1}
     parameterDict2 = {"param1": 5, "param2": 4}
     model = None
     hardwareRequirements = {}
     configFile = None
     task = SpecificDeviceTask( taskName
                              , parameterDict
                              , model
                              , hardwareRequirements
                              , "test" #filename
                              , "test" #function
                              , configFile
                              )
     deviceHolder = DeviceHolder(maxSize)
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceOne.name
                                     , self.deviceOne.ipAdress
                                     , self.deviceOne.port 
                                     , self.deviceOne.hardwareConfig
                                     , self.deviceOne.initTask
                                     )
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceTwo.name
                                     , self.deviceTwo.ipAdress
                                     , self.deviceTwo.port 
                                     , self.deviceTwo.hardwareConfig
                                     , self.deviceTwo.initTask
                                     )
     deviceHolder.addDevice(self.deviceOne, task.taskName, task.parameterDict)
     deviceHolder.addDevice(self.deviceTwo, task.taskName, parameterDict2)
     deviceHolder.broadcastTask(task)
     self.assertEqual( deviceHolder.get_finishedTasks(taskName)[0].resultDict
                     , {'result_0': 6 } 
                     , msg = "Wrong entries for finished tasks"
                     )
     self.assertEqual( deviceHolder.get_finishedTasks(taskName)[1].resultDict
                     , {'result_0': 9 } 
                     , msg = "Wrong entries for finished tasks"
                     )
     with self.assertRaises(Exception) as context:
         deviceHolder.get_finishedTasks("hello")
     self.assertTrue("No task with name" in str(context.exception))
예제 #5
0
 def testStopTask(self):
     "Stop the task on server. Remove the task from the openTaskDict"
     taskName = "task_one"
     maxSize = 3
     parameterDict = {"param1": 5, "param2": 1}
     model = None
     hardwareRequirements = {}
     configFile = None
     task = SpecificDeviceTask( taskName
                              , parameterDict
                              , model
                              , hardwareRequirements
                              , "test" #filename
                              , "test" #function
                              , configFile
                              )
     deviceHolder = DeviceHolder( maxSize
                                )
     deviceHolder.addDevice(self.deviceOne, task.taskName, task.parameterDict)
     deviceHolder.addDevice(self.deviceTwo, task.taskName, task.parameterDict)
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceOne.name
                                     , self.deviceOne.ipAdress
                                     , self.deviceOne.port 
                                     , self.deviceOne.hardwareConfig
                                     , self.deviceOne.initTask
                                     )
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceTwo.name
                                     , self.deviceTwo.ipAdress
                                     , self.deviceTwo.port 
                                     , self.deviceTwo.hardwareConfig
                                     , self.deviceTwo.initTask
                                     )
     deviceHolder.broadcastTask(task)
     self.assertEqual( {'task_one': {'param1': 5, 'param2': 1}}
                     , self.deviceOne._openTaskDict
                     , msg = "Wrong entries for openTaskDict"
                     )
     deviceHolder.stopTask(task.taskName)
     self.assertEqual( {}
                     , self.deviceOne._openTaskDict
                     , msg = "Wrong entries for openTaskDict"
                     )
예제 #6
0
 def startTask(self,
               taskType=0,
               parameterDict={},
               model=None,
               hardwareRequirements={},
               filePath=None,
               executeFunction=None,
               configFile=None,
               priority=False,
               numDevices=-1,
               cluster=None):
     """!
     @param executeFunction name of function, which should be executed in filePath
     """
     # defaultTask
     taskName = "task_" + str(WorkflowManager.taskID
                              ) + "_" + datetime.datetime.now().isoformat()
     WorkflowManager.taskID += 1
     if taskType == 0:
         task = DefaultTask(taskName, parameterDict, model,
                            hardwareRequirements, filePath, executeFunction,
                            configFile, numDevices)
     if taskType == 1:
         task = SpecificDeviceTask(taskName, parameterDict, model,
                                   hardwareRequirements, filePath,
                                   executeFunction, configFile)
     # request possibility from selector if task is feasible
     request_status = self._sendTaskRequest(task)
     #task accepted
     if request_status:
         self.selector.addTask2Queue(task, priority)
         self.logger.log().info("task accepted")
     # task rejected
     else:
         taskName = None
         self.logger.log().info(
             "task was not accepted - change your constraints?")
     self.logger.log().debug("start task." + str(locals()))
     return taskName
예제 #7
0
 def setUp(self):
     taskName = "task_one"
     maxSize = 3
     parameterDict = { "device_one": {"param1": 5, "param2": 1}
                     , "device_two": {"param1": 5, "param2": 1}
                     }
     model = None
     hardwareRequirements = {}
     configFile = None
     self.task = SpecificDeviceTask( taskName
                                   , parameterDict
                                   , model
                                   , hardwareRequirements
                                   , "test" #filename
                                   , "test" #function
                                   , configFile
                                   )
     server = "https://127.0.0.0.1:7777"
     client_key = "000"
     name1 = "device_one"
     name2 = "device_two"
     if TEST_MODE:
         ipAdress1 = "client1"
         ipAdress2 = "client2"
     else:
         ipAdress1 = "127.0.0.1"
         ipAdress2 = "127.0.0.1"
     self.dartRuntime = DartRuntime( server
                                   , client_key
                                   , TEST_MODE
                                   , ERROR_PROBABILITY
                                   )
     self.deviceOne = DeviceSingle( name = name1
                                  , ipAdress = ipAdress1
                                  , port = 2883
                                  , dartRuntime = self.dartRuntime
                                  , physicalName = None
                                  , hardwareConfig = None
                                  , taskDict = {}
                                  , initTask = None
                                  )
     self.deviceTwo = DeviceSingle( name = name2
                                  , ipAdress = ipAdress2
                                  , port = 2883
                                  , dartRuntime = self.dartRuntime
                                  , physicalName = None
                                  , hardwareConfig = None
                                  , taskDict = {}
                                  , initTask = None
                                  )
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceOne.name
                                     , self.deviceOne.ipAdress
                                     , self.deviceOne.port 
                                     , self.deviceOne.hardwareConfig
                                     , self.deviceOne.initTask
                                     )
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceTwo.name
                                     , self.deviceTwo.ipAdress
                                     , self.deviceTwo.port 
                                     , self.deviceTwo.hardwareConfig
                                     , self.deviceTwo.initTask
                                     )