Beispiel #1
0
def getFromCouch(jobId, objectId, serviceName = "", verbose = True, url = "http://localhost:5984/hsn", timeout = 10):
	'''
	Wrapper for getting objects from couchDB.
	@param jobId: The job that the data belongs to.
	@param objectId: The objectId that the data belongs to.
	@param serviceName: The name of the service that was reported (reporter configuration).
	@param url: The location of the couch database REST api.
	@param timeout: Number of seconds to wait for connection.
	@return: dictionary with the data if the object was found and otherwise None
	'''
	if len(serviceName) > 0:
		serviceName = ":%s" % serviceName
	objUrl = "%s/%d:%d%s" % (url, long(jobId), long(objectId), serviceName)
	objUrl = urllib.quote(objUrl, safe = ":/")
	try:
		handle = getUrlHandle(objUrl, None, "GET")
	except urllib2.URLError as e:
		logging.error(e)
		return None
	import json
	text = ''.join(handle.readlines())
	if verbose:
		logging.info(text)
	dictionary = json.loads(text)
	return dictionary
Beispiel #2
0
	def initStart(cls, proc, autoStop = True, expected = "is running.\n", service = True):
		'''
		Used for starting a process which has a startup file in the init.d directory.
		If the process return code was different than 0 then an InitException will be raised.
		If expected is passed and the process isn't running then an InitException will be raised.
		@param proc: the name of the startup script in the init.d directory.
		@param autoStop: if True then the process will be stopped when stopStartedInits is called.
		@param expected: the string that is expected to end the status string from an init script in it's running state. If None is passed then the status won't be checked.
		'''
		if service:
			procFull = "service %s" % proc
		else:
			procFull = "/etc/init.d/%s" % proc
			
		cls.initStop(proc, verbose = False)
		ret = Console.call("%s %s" % (procFull, "start"))
		if ret[0] != 0:
			logging.error(ret)
			raise InitException("Couldn't start init")
		if expected is not None:
			if not cls.initStatus(proc, expected):
				raise InitException("%s didn't start" % proc)
		if autoStop:
			cls.inits.append((proc, expected))
		logging.info("Init '%s' started" % proc)
Beispiel #3
0
	def __init__(self, jobId = 1):
		'''
		Gathers all information about job from "hc j d".
		@param jobId: The id of the job about which the details will be gathered.
		'''
		self.jobId = jobId
		lines = Console.call("hc j d %s" % self.jobId)[1].split('\n')
		for line in lines:
			if re.search(r'^\s', line) is None:
				continue
			elif re.search(r'task_count', line) is None:
				ret = re.search(r'\s*(\S+)\s*(\S.*)', line) #\s*([A-Z]+)
				if ret is None:
					logging.warning("job details fail: %s" % line)
					continue
				logging.debug("job details: %s = %s" % (ret.group(1), ret.group(2)))
				self.properties[ret.group(1)] = '%s' % ret.group(2)
			else:
				ret = re.search(r'\s*task_count_(\S+)\s*(\d+)\/(\d+)', line)
				if ret is None:
					logging.error("job details fail: %s" % line)
					continue
				logging.debug("job details: task_count_%s = %s/%s" % (ret.group(1), ret.group(2), ret.group(3)))
				self.properties[ret.group(1)] = (ret.group(2), ret.group(3))
Beispiel #4
0
		Starter.initStart("hsn2-data-store")
		Starter.initStart("hsn2-swf-cve")
		Starter.initStart("hsn2-js-sta")
		Starter.initStart("hsn2-webclient")
		Starter.initStart("hsn2-file-feeder")
		Starter.initStart("hsn2-swfScanner")
		Starter.initStart("hsn2-clamavNugget")
		Starter.initStart("hsn2-pdfFox")
		Starter.initStart("hsn2-archiveInflate")
		Starter.initStart("hsn2-mimeRecognizer")
		Starter.waitCouchDB()
		Configuration.deleteCouchDB()
		Starter.initStart("hsn2-reporter")

	except Exception as e:
		logging.error(e)
	finally:
		Starter.stopStartedInits()
		Website.shutdownWebsites()
		agg.aggregate(takeFrom = "/var/log/hsn2")
		agg.aggregate(takeFrom = "/var/log/couchdb")
		Backup.restoreFiles()

#_start_jar()
#{
#	java -jar $INSTALL_PATH/$1/hsn2-$1.jar `cat $TEST_DIR/params/$1` &
#	sleep 1
#}
#
#_stop_jar()
#{