Ejemplo n.º 1
0
    def heartbeat(self):
        while True:
            try:
                url = '%s/node/%s' % (self.grid_url, str(self.node_id))
                request = JSONHTTPRequest('POST', url, {
                    'cpu': self.mon.cpu(),
                }, self.auth_header)
            except (HTTPException, URLError) as e:

                node_utils.request_error_cli(
                    e,
                    "Heatbeat Failed: Unable to establish a connection to the grid"
                )

                if self.retry_attempts < self.RETRY_MAX_ATTEMPTS:
                    try:
                        self.node_id = self.register_node()
                    except ServerUnavailableException as e:
                        self.retry_attempts += 1
                else:
                    print "Unable to connect to The Grid after %d unsuccessful attempts" % (
                        self.RETRY_MAX_ATTEMPTS)

                    # Reset the node state to clean up any running tasks
                    self.reset_node_state()

                    thread.interrupt_main()

            time.sleep(self.HEARTBEAT_INTERVAL)
Ejemplo n.º 2
0
	def heartbeat(self):
		while True:
			try:
				url = '%s/node/%s' % (self.grid_url, str(self.node_id))
				request = JSONHTTPRequest( 'POST', url, { 
					'cpu': self.mon.cpu(),
				}, self.auth_header)
			except (HTTPException, URLError) as e:
				
				node_utils.request_error_cli(e, 
					"Heatbeat Failed: Unable to establish a connection to the grid")

				if self.retry_attempts < self.RETRY_MAX_ATTEMPTS:
					try:
						self.node_id = self.register_node()
					except ServerUnavailableException as e:
						self.retry_attempts += 1
				else:	
					print "Unable to connect to The Grid after %d unsuccessful attempts" % (self.RETRY_MAX_ATTEMPTS)

					# Reset the node state to clean up any running tasks
					self.reset_node_state()

					thread.interrupt_main()

			time.sleep(self.HEARTBEAT_INTERVAL)
Ejemplo n.º 3
0
	def get_task_file(self, task):
		try:
			url = "%s/job/%s/files/%s" % (self.grid_url, task.job_id, task.filename)
			request = HTTPRequest( 'GET', url, "", self.auth_header)
		except (HTTPException, URLError) as e:
			node_utils.request_error_cli(e, "Unable to establish a connection to The Grid")
			sys.exit(1)
	
		# This will be horrible with large files

		fp = open(task.input_path, 'w+')
		fp.write(request.response)
		fp.close()
Ejemplo n.º 4
0
    def get_task_file(self, task):
        try:
            url = "%s/job/%s/files/%s" % (self.grid_url, task.job_id,
                                          task.filename)
            request = HTTPRequest('GET', url, "", self.auth_header)
        except (HTTPException, URLError) as e:
            node_utils.request_error_cli(
                e, "Unable to establish a connection to The Grid")
            sys.exit(1)

        # This will be horrible with large files

        fp = open(task.input_path, 'w+')
        fp.write(request.response)
        fp.close()
Ejemplo n.º 5
0
	def send_task_output(self, task):
	
		# Send the results of stdout
		try:
			url = '%s/job/%s/output/%s' % (self.grid_url, str(task.job_id), task.output_name + ".o")
			request = FileHTTPRequest( 'PUT', url, task.output_path, self.auth_header )
		except (HTTPException, URLError) as e:
			node_utils.request_error_cli(e, "Unable to establish a connection to the grid")

		# Send the results of stderr
		try:
			url = '%s/job/%s/output/%s' % (self.grid_url, str(task.job_id), task.output_name + ".e")
			request = FileHTTPRequest( 'PUT', url, task.error_path, self.auth_header )
		except (HTTPException, URLError) as e:
			node_utils.request_error_cli(e, "Unable to establish a connection to the grid")
Ejemplo n.º 6
0
	def register_node(self):
		try:
			request = JSONHTTPRequest( 'POST', self.grid_url + '/node', { 
				'host': self.host,
				'port': self.port,
				'cores': self.cores,
				'programs': self.programs,
				'cost': self.cost,
			}, self.auth_header)
		except (HTTPException, URLError) as e:
			node_utils.request_error_cli(e, "Unable to establish a connection to The Grid")
			raise ServerUnavailableException("The Grid is currently unavailable.")

		# Reset the node state in the event of Server failure
		self.reset_node_state()

		return request.response['node_id']
Ejemplo n.º 7
0
	def finish_task(self, task, kill_msg = None):

		self.send_task_output(task)
		self.cleanup_task_files(task)

		# Inform the server the task is complete
		try:
			url = '%s/job/%s/workunit' % (self.grid_url, str(task.job_id))
			request = JSONHTTPRequest( 'POST', url, { 
				'work_unit_id': task.work_unit_id,
				'kill_msg': kill_msg,
			}, self.auth_header)
		except (HTTPException, URLError) as e:
			node_utils.request_error_cli(e, "Unable to establish a connection to the grid")

		# Update the task internally to reflect that the server has 
		# received all files and the complete status.
		task.finish()
Ejemplo n.º 8
0
    def finish_task(self, task, kill_msg=None):

        self.send_task_output(task)
        self.cleanup_task_files(task)

        # Inform the server the task is complete
        try:
            url = '%s/job/%s/workunit' % (self.grid_url, str(task.job_id))
            request = JSONHTTPRequest('POST', url, {
                'work_unit_id': task.work_unit_id,
                'kill_msg': kill_msg,
            }, self.auth_header)
        except (HTTPException, URLError) as e:
            node_utils.request_error_cli(
                e, "Unable to establish a connection to the grid")

        # Update the task internally to reflect that the server has
        # received all files and the complete status.
        task.finish()
Ejemplo n.º 9
0
    def register_node(self):
        try:
            request = JSONHTTPRequest(
                'POST', self.grid_url + '/node', {
                    'host': self.host,
                    'port': self.port,
                    'cores': self.cores,
                    'programs': self.programs,
                    'cost': self.cost,
                }, self.auth_header)
        except (HTTPException, URLError) as e:
            node_utils.request_error_cli(
                e, "Unable to establish a connection to The Grid")
            raise ServerUnavailableException(
                "The Grid is currently unavailable.")

        # Reset the node state in the event of Server failure
        self.reset_node_state()

        return request.response['node_id']
Ejemplo n.º 10
0
    def send_task_output(self, task):

        # Send the results of stdout
        try:
            url = '%s/job/%s/output/%s' % (self.grid_url, str(
                task.job_id), task.output_name + ".o")
            request = FileHTTPRequest('PUT', url, task.output_path,
                                      self.auth_header)
        except (HTTPException, URLError) as e:
            node_utils.request_error_cli(
                e, "Unable to establish a connection to the grid")

        # Send the results of stderr
        try:
            url = '%s/job/%s/output/%s' % (self.grid_url, str(
                task.job_id), task.output_name + ".e")
            request = FileHTTPRequest('PUT', url, task.error_path,
                                      self.auth_header)
        except (HTTPException, URLError) as e:
            node_utils.request_error_cli(
                e, "Unable to establish a connection to the grid")