Exemplo n.º 1
0
    def stopCluster(self, task, params):
        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__())

        # Stop cluster
        ec2_controller.stop_cluster(configurationFilePath, clusterId)

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

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

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

        # terminate cluster
        login = self.getCurrentUser()['login']
        taskId = taskToStop['_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)
        if not ec2_controller.stop_cluster(configurationFilePath, clusterId):
            raise RestException('Error while terminate cluster. {}'.format(working_dir), code=403)

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

        # FIXME kill task
        # FIXME backup the data
        # FIXME stop cluster once task

        return taskToStop