def _updateConfiguration(self, projectId): # create cluster config 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, projectId) # configurationFilePath, tasks, template_file tasks = self.find({ "parentType": "folder", "parentId": projectId }) return ec2_controller.create_configuration(configurationFilePath, tasks, template_file_path)
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