Ejemplo n.º 1
0
    def __init__(self, configuration_file, log_file):
        configuration_loader = Loader(configuration_file)
        self.l = Logger(log_file, "a")

        self.idgenerator = IDGenerator()
        self.incarnationid = self.idgenerator.generate()

        self.l.log("Incarnation ID: " + self.incarnationid)

        if not configuration_loader.has_property(PROBABILITY_TO_RUN_PROPERTY) or not configuration_loader.has_property(SLEEP_TIME_PROPERTY):
            print "Invalid Configuration File"
            self.l.log("Invalid Configuration File")
            exit()

        self.probability_to_run = float(configuration_loader.get_property(PROBABILITY_TO_RUN_PROPERTY))
        self.sleep_time = float(configuration_loader.get_property(SLEEP_TIME_PROPERTY))
Ejemplo n.º 2
0
from firebase import firebase
import IDGenerator

firebase = firebase.FirebaseApplication(
    'https://smartparkingsystem-bca72.firebaseio.com/', None)
id = IDGenerator.ID()


class ParkingSlot:
    def __init__(self, slotNo, type, allotted=False):
        self.slotNo = slotNo
        self.type = type
        self.allotted = allotted

    def getJSONRep(self):
        json = {}
        json["SlotNo"] = self.slotNo
        json["Type"] = self.type
        json["Allotted"] = self.allotted
        return json


class ParkingSlots:
    def __init__(self):
        pass

    def insert(self, parkingSlot):
        slotID = id.getNextParkingSlotID()
        data = parkingSlot.getJSONRep()
        firebase.put("ParkingSlots", slotID, data)
        print("Inserted into database")
INTRUSIVENESS_METER_HOME_PROPERTY = "INTRUSIVENESS_METER_HOME"
INTRUSIVENESS_METER_HOME = os.environ["INTRUSIVENESS_METER_HOME"]

SOURCE_DIRECTORY = INTRUSIVENESS_METER_HOME + "/source"
HADOOP_INFO_SCRIPT = SOURCE_DIRECTORY + "/hadoop_info.sh"

ERROR_LOG_FILE = "hadoop_running.error"
LOG_FILE = "hadoop_running.log"

def there_are_running_benchmarks():
    running = False
    # FIXME hard coded
    input = os.popen("bash " + HADOOP_INFO_SCRIPT + " -r").read()
    if input == "true":
        running = True
    return running

error_log = Logger(ERROR_LOG_FILE, "a")
logger = Logger(LOG_FILE, "a")
idGenerator = IDGenerator() 
incarnationid = idGenerator.generate()

logger.log("Incarnation ID: " + incarnationid)
error_log.log("Incarnation ID: " + incarnationid)

SLEEP_TIME = 1

while True:
    logger.log(str(there_are_running_benchmarks()))
    time.sleep(SLEEP_TIME)
Ejemplo n.º 4
0
class Controller:

    def __init__(self, configuration_file, log_file):
        configuration_loader = Loader(configuration_file)
        self.l = Logger(log_file, "a")

        self.idgenerator = IDGenerator()
        self.incarnationid = self.idgenerator.generate()

        self.l.log("Incarnation ID: " + self.incarnationid)

        if not configuration_loader.has_property(PROBABILITY_TO_RUN_PROPERTY) or not configuration_loader.has_property(SLEEP_TIME_PROPERTY):
            print "Invalid Configuration File"
            self.l.log("Invalid Configuration File")
            exit()

        self.probability_to_run = float(configuration_loader.get_property(PROBABILITY_TO_RUN_PROPERTY))
        self.sleep_time = float(configuration_loader.get_property(SLEEP_TIME_PROPERTY))

    def choose_benchmark(self, benchmarks):
        return random.sample(benchmarks, 1)[0]

    def run_benchmark(self, benchmark, hadoop_script_conf_file):
        os.system("bash " + HADOOP_SCRIPT + " " + benchmark + " " + hadoop_script_conf_file)

    def thereAreRunningBenchmarks(self):
        running = False
	# FIXME hard coded
        input = os.popen("bash " + HADOOP_INFO_SCRIPT + " -r").read()
        if input == "true":
            running = True
        return running

    def run(self, benchmarks, HADOOP_SCRIPT_CONF_FILE):
        self.l.log("starting execution")
        chosen_benchmark = ""
        while True:
            random_number = random.random()
            self.l.log("random number:" + str(random_number))
            if random_number < self.probability_to_run:
                if self.thereAreRunningBenchmarks():
                    self.l.log("gave up of starting. There are running benchmarks")
                else:
                    self.l.log("will start benchmark")
                    # this logic should be in choose_benchmark
                    if chosen_benchmark == "dfwrite":
                        chosen_benchmark = "dfread"
                    elif chosen_benchmark == "dfread":
                        chosen_benchmark = "dfclean"
                    elif chosen_benchmark == "teragen":
                        chosen_benchmark = "terasort"
                    elif chosen_benchmark == "terasort":
                        chosen_benchmark = "teravalidate"
                    elif chosen_benchmark == "teravalidate":
                        chosen_benchmark = "teraclean"
                    else:
                        chosen_benchmark = self.choose_benchmark(benchmarks)
	
                    self.l.log("chosen benchmark: " + chosen_benchmark)
                    self.l.log("will start benchmark:" + chosen_benchmark)
                    self.run_benchmark(chosen_benchmark, HADOOP_SCRIPT_CONF_FILE)
                    self.l.log("started benchmark: " + chosen_benchmark)
            else:
                self.l.log("Decided not to run")
            time.sleep(self.sleep_time)