예제 #1
0
def __execution_loop(vm: VirtualMachine, task: Task):

    # Start the VM in the cloud
    status = vm.deploy()

    logging.info("<Executor {}-{}>: Instance-id {} - Status {}".format(
        task.task_id, vm.instance_id, vm.instance_id, status))
    if status:
        try:
            vm.prepare_vm()
        except Exception as e:
            logging.error(e)

    try:
        __prepare_daemon(vm)
    except Exception as e:
        logging.error(e)

    # indicate that the VM is ready to execute
    vm.ready = True

    # start Execution when instance is RUNNING
    if vm.state == CloudManager.RUNNING:

        # create a executor and start task
        executor = Executor(task=task, vm=vm)
        # start the executor loop to execute the task
        executor.thread.start()
예제 #2
0
def test_dispatcher_with_daemon():
    instance = InstanceType(provider=CloudManager.EC2,
                            instance_type='t2.micro',
                            image_id='ami-09685b54c80020d8c',
                            ebs_device_name='/dev/xvdf',
                            restrictions={
                                'on-demand': 1,
                                'preemptible': 1
                            },
                            prices={
                                'on-demand': 0.001,
                                'preemptible': 0.000031
                            })

    task = Task(task_id=2,
                command="ls",
                runtime={'t2.micro': 100},
                generic_ckpt=False)

    vm = VirtualMachine(instance_type=instance, market='on-demand')

    vm.instance_id = 'i-0dd21b2167699e7dd'

    __prepare_logging()

    __execution_loop(vm=vm, task=task)
예제 #3
0
    def __run(self, vm: VirtualMachine, model: Poisson):
        while not vm.ready:
            time.sleep(1)

        while self.running:

            time.sleep(1)

            # if global_state is running check if a termination occurs
            if vm.state == CloudManager.RUNNING and vm.ready:
                if model.event_happened():
                    vm.terminate(delete_volume=False)
                    return
예제 #4
0
    def __interruption_handle(self):

        # Move task to other VM
        # self.semaphore.acquire()

        if not self.loader.cudalign_task.has_task_finished():
            self.loader.cudalign_task.stop_execution()

        # logging.info("Entrou no interruption_handle")

        # getting volume-id
        if self.loader.file_system_conf.type == EC2Manager.EBS:
            self.ebs_volume_id = self.task_dispatcher.vm.volume_id

        # logging.info("Pegou o id do EBS: {}".format(self.ebs_volume_id))

        # See in which VM we wiil restart
        current_time = self.start_timestamp - datetime.now()

        instance_type, market = self.scheduler.choose_restart_best_instance_type(
            cudalign_task=self.loader.cudalign_task,
            deadline=self.loader.deadline_seconds,
            current_time=current_time.total_seconds()
        )

        # logging.info("Escolheu instancia {} do tipo {}".format(instance_type.type, market))

        if self.loader.cudalign_task.has_task_finished():
            new_vm = VirtualMachine(
                instance_type=instance_type,
                market=market,
                loader=self.loader,
                volume_id=self.ebs_volume_id
            )

            # logging.info("Criou a nova vm!")

            dispatcher = Dispatcher(vm=new_vm, loader=self.loader)

            # check if the VM need to be register on the simulator
            if self.loader.simulation_conf.with_simulation and new_vm.market == CloudManager.PREEMPTIBLE:
                self.simulator.register_vm(new_vm)

            # self.semaphore.acquire()

            self.terminated_dispatchers.append(self.task_dispatcher)
            self.task_dispatcher = dispatcher

            # self.semaphore.release()

            self.__start_dispatcher()
예제 #5
0
def test_vm_with_EBS(volume_id=''):
    instance = InstanceType(provider=CloudManager.EC2,
                            instance_type='t2.micro',
                            image_id='ami-09685b54c80020d8c',
                            memory=1,
                            vcpu=1,
                            ebs_device_name='/dev/xvdf',
                            restrictions={
                                'on-demand': 1,
                                'preemptible': 1
                            },
                            prices={
                                'on-demand': 0.001,
                                'preemptible': 0.000031
                            },
                            gflops=0.0)

    # task = Task(
    #     task_id=2,
    #     memory=0.2,
    #     command="ls",
    #     io=0,
    #     runtime={'t2.nano': 100}
    # )

    vm = VirtualMachine(instance_type=instance, market='preemptible')

    __prepare_logging()

    if volume_id is not None:
        vm.volume_id = volume_id

    vm.deploy()

    vm.prepare_vm()

    status = vm.terminate(delete_volume=False)

    if status:
        logging.info("<VirtualMachine {}>: Terminated with Success".format(
            vm.instance_id, status))
예제 #6
0
    def __build_dispatcher(self):

        instance_type, market = self.scheduler.choose_initial_best_instance_type(self.loader.cudalign_task,
                                                                                 self.loader.deadline_seconds)

        # Create the Vm that will be used by the dispatcher
        vm = VirtualMachine(
            instance_type=instance_type,
            market=market,
            loader=self.loader
        )

        # than a dispatcher, that will execute the tasks, is create

        dispatcher = Dispatcher(vm=vm, loader=self.loader)

        # check if the VM need to be register on the simulator
        if self.loader.simulation_conf.with_simulation and vm.market == CloudManager.PREEMPTIBLE:
            self.simulator.register_vm(vm)

        # self.semaphore.acquire()

        self.task_dispatcher = dispatcher
예제 #7
0
def test_preemptible_virtual_machine():
    instance = InstanceType(provider=CloudManager.EC2,
                            instance_type='t2.micro',
                            image_id='ami-0d1a4eacad59b7a5b',
                            memory=1,
                            vcpu=1,
                            restrictions={
                                'on-demand': 1,
                                'preemptible': 1
                            },
                            prices={
                                'on-demand': 0.001,
                                'preemptible': 0.000031
                            },
                            gflops=0.0)

    # task = Task(
    #     task_id=2,
    #     memory=0.2,
    #     command="ls",
    #     io=0,
    #     runtime={'t2.nano': 100}
    # )

    vm = VirtualMachine(instance_type=instance, market='preemptible')

    __prepare_logging()

    vm.deploy()

    vm.prepare_vm()

    status = vm.terminate()

    if status:
        logging.info("<VirtualMachine {}>: Terminated with Success".format(
            vm.instance_id, status))
예제 #8
0
def main():
    parser = argparse.ArgumentParser(
        description='Creating a t2.micro instance to check EBS content')
    parser.add_argument('--input_path',
                        help="Path where there are all input files",
                        type=str,
                        default=None)
    parser.add_argument('--task_file',
                        help="task file name",
                        type=str,
                        default=None)
    parser.add_argument('--env_file',
                        help="env file name",
                        type=str,
                        default=None)
    # parser.add_argument('--map_file', help="map file name", type=str, default=None)
    parser.add_argument('--deadline_seconds',
                        help="deadline (seconds)",
                        type=int,
                        default=None)
    # parser.add_argument('--ac_size_seconds', help="Define the size of the Logical Allocation Cycle (seconds)",
    #                     type=int, default=None)

    parser.add_argument(
        '--revocation_rate',
        help=
        "Revocation rate of the spot VMs [0.0 - 1.0] (simulation-only parameter)",
        type=float,
        default=None)

    parser.add_argument('--log_file',
                        help="log file name",
                        type=str,
                        default=None)
    parser.add_argument('--command',
                        help='command para o client',
                        type=str,
                        default='')
    parser.add_argument('volume_id', help="Volume id to be attached", type=str)

    args = parser.parse_args()
    loader = Loader(args=args)
    volume_id = args.volume_id

    instance = InstanceType(provider=CloudManager.EC2,
                            instance_type='t2.micro',
                            image_id='ami-07ae9c26b070d6a66',
                            ebs_device_name='/dev/xvdf',
                            restrictions={
                                'on-demand': 1,
                                'preemptible': 1
                            },
                            prices={
                                'on-demand': 0.001,
                                'preemptible': 0.000031
                            })

    vm = VirtualMachine(instance_type=instance,
                        market='preemptible',
                        loader=loader)

    __prepare_logging()

    if volume_id is not None:
        vm.volume_id = volume_id

    vm.deploy()

    vm.prepare_vm()