Exemplo n.º 1
0
    def startTask(self, task, params):
        # create cluster config
        if not self._updateConfiguration(task["parentId"].__str__()):
            raise RestException('Invalid configuration.', code=403)

        # start cluster
        # FIXME not yet | if not ec2_controller.start_cluster(configurationFilePath, clusterId):
        # FIXME not yet |     raise RestException('Error while starting cluster. {}'.format(working_dir), code=404)

        # FIXME queue the task
        # FIXME backup the data
        # FIXME stop cluster once task is done

        # create cluster config
        clusterId = "%s_%s" % (task['task'], task['_id'].__str__())
        working_dir = self.model('setting').get(constants.PluginSettings.STARCLUSTER_WORK_DIRECTORY)
        configurationFilePath = os.path.join(working_dir, task["parentId"].__str__())

        # Start task on cluster
        ec2_controller.start_cluster(configurationFilePath, clusterId, True)

        # Update task status
        task['status'] = constants.CloudTaskStatus.RUNNING
        self.model('task', 'ec2_cloud').updateTask(task)
Exemplo n.º 2
0
    def start(self, name, params):
        taskToStartCursor = self.model('task', 'ec2_cloud').find({'name': name})

        if taskToStartCursor.count() == 0:
            raise RestException('No task found.', code=401)

        taskToStart = taskToStartCursor.next()
        if taskToStart['status'] != 1:
            raise RestException('Invalid task status {}.'.format(constants.CloudTaskStatus.toString(taskToStart['status'])), code=402)



        # create cluster config
        login = self.getCurrentUser()['login']
        taskId = taskToStart['_id'].__str__()
        clusterId = "%s_%s" % (login, taskId)
        template_file_path = self.model('setting').get(constants.PluginSettings.STARCLUSTER_TEMPLATE_CONFIGURATION_PATH)
        working_dir = self.model('setting').get(constants.PluginSettings.STARCLUSTER_WORK_DIRECTORY)
        configurationFilePath = os.path.join(working_dir, login, taskId)

        # configurationFilePath, task, template_file, clusterName
        if not ec2_controller.create_configuration(configurationFilePath, taskToStart, template_file_path, clusterId):
            raise RestException('Invalid configuration {}.'.format(working_dir), code=403)

        # start cluster
        if not ec2_controller.start_cluster(configurationFilePath, clusterId):
            raise RestException('Error while starting cluster. {}'.format(working_dir), code=404)

        # FIXME queue the task
        # FIXME backup the data
        # FIXME stop cluster once task is done

        taskToStart['status'] = constants.CloudTaskStatus.RUNNING
        self.model('task', 'ec2_cloud').updateTask(taskToStart)

        return taskToStart