def create(self, user, taskflow, task): """ Create a new task associated with a taskflow :param user: The user creating the task. :param taskflow: The taskflow that the task will be part of. :param task: The task document. """ task['taskFlowId'] = taskflow['_id'] task['status'] = 'created' task['log'] = [] now = datetime.datetime.utcnow() task['created'] = now model = ModelImporter.model('taskflow', 'taskflow') doc = self.setUserAccess(task, user, level=AccessType.ADMIN, save=True) # increment the number of active tasks query = { '_id': taskflow['_id'] } model.increment(query, 'activeTaskCount', 1) send_status_notification('task', doc) return doc
def create_ebs(self, user, profileId, name, zone, size, fs): volume = { 'name': name, 'zone': zone, 'size': size, 'type': VolumeType.EBS, 'ec2': { 'id': None }, 'profileId': profileId, 'status': VolumeState.CREATED, 'log': [] } if fs: volume['fs'] = fs # Add userId field to make search for a user volumes easier volume['userId'] = user['_id'] self.setUserAccess(volume, user=user, level=AccessType.ADMIN) group = { '_id': ObjectId(self.get_group_id()) } self.setGroupAccess(volume, group, level=AccessType.ADMIN) self.save(volume) send_status_notification('volume', volume) return volume
def create(self, user, taskflow, task): """ Create a new task associated with a taskflow :param user: The user creating the task. :param taskflow: The taskflow that the task will be part of. :param task: The task document. """ task['taskFlowId'] = taskflow['_id'] task['status'] = 'created' task['log'] = [] now = datetime.datetime.utcnow() task['created'] = now model = self.model('taskflow', 'taskflow') doc = self.setUserAccess(task, user, level=AccessType.ADMIN, save=True) # increment the number of active tasks query = { '_id': taskflow['_id'] } model.increment(query, 'activeTaskCount', 1) send_status_notification('task', doc) return doc
def create_ebs(self, user, profileId, name, zone, size, fs): volume = { 'name': name, 'zone': zone, 'size': size, 'type': VolumeType.EBS, 'ec2': { 'id': None }, 'profileId': profileId, 'status': VolumeState.CREATED, 'log': [] } if fs: volume['fs'] = fs # Add userId field to make search for a user volumes easier volume['userId'] = user['_id'] self.setUserAccess(volume, user=user, level=AccessType.ADMIN) group = {'_id': ObjectId(self.get_group_id())} self.setGroupAccess(volume, group, level=AccessType.ADMIN) self.save(volume) send_status_notification('volume', volume) return volume
def update_job(self, user, job): job_id = job["_id"] current_job = self.load(job_id, user=user, level=AccessType.WRITE) new_status = job["status"] if current_job["status"] != new_status: send_status_notification("job", job) return self.save(job)
def update_job(self, user, job): job_id = job['_id'] current_job = self.load(job_id, user=user, level=AccessType.WRITE) new_status = job['status'] if current_job['status'] != new_status: send_status_notification('job', job) return self.save(job)
def create(self, user, taskflow): taskflow['status'] = TaskFlowState.CREATED taskflow['log'] = [] taskflow = self.setUserAccess( taskflow, user, level=AccessType.ADMIN, save=True) send_status_notification('taskflow', taskflow) return taskflow
def update_status(self, user, id, status): # Load first to force access check job = self.load(id, user=user, level=AccessType.WRITE) if status and job['status'] != status: job['status'] = status send_status_notification('job', job) job = self.save(job) return job
def create(self, user, taskflow): taskflow['status'] = TaskFlowState.CREATED taskflow['log'] = [] taskflow = self.setUserAccess( taskflow, user, level=AccessType.ADMIN, save=True) send_status_notification('taskflow', taskflow) return taskflow
def update_status(self, user, id, status): # Load first to force access check job = self.load(id, user=user, level=AccessType.WRITE) if status and job["status"] != status: job["status"] = status send_status_notification("job", job) job = self.save(job) return job
def update_task(self, user, task, status=None): if status and task['status'] != status: task['status'] = status task = self.save(task) # Update the state of the parent taskflow ModelImporter.model('taskflow', 'taskflow').update_state( user, task['taskFlowId']) send_status_notification('task', task) return task
def update_task(self, user, task, status=None): if status and task['status'] != status: task['status'] = status task = self.save(task) # Update the state of the parent taskflow self.model('taskflow', 'taskflow').update_state( user, task['taskFlowId']) send_status_notification('task', task) return task
def update_volume(self, user, volume): volume_id = volume['_id'] current_volume = self.load(volume_id, user=user, level=AccessType.WRITE) previous_status = current_volume['status'] current_volume.update(volume) if current_volume['status'] != previous_status: send_status_notification('volume', current_volume) return self.save(current_volume)
def update_volume(self, user, volume): volume_id = volume['_id'] current_volume = self.load(volume_id, user=user, level=AccessType.WRITE) previous_status = current_volume['status'] current_volume.update(volume) if current_volume['status'] != previous_status: send_status_notification('volume', current_volume) return self.save(current_volume)
def update_cluster(self, user, cluster): # Load first to force access check cluster_id = cluster['_id'] current_cluster = self.load(cluster_id, user=user, level=AccessType.WRITE) previous_status = current_cluster['status'] current_cluster.update(cluster) # If the status has changed create a notification if current_cluster['status'] != previous_status: send_status_notification('cluster', current_cluster) return self.save(current_cluster)
def update_cluster(self, user, cluster): # Load first to force access check cluster_id = cluster['_id'] current_cluster = self.load(cluster_id, user=user, level=AccessType.WRITE) previous_status = current_cluster['status'] current_cluster.update(cluster) # If the status has changed create a notification if current_cluster['status'] != previous_status: send_status_notification('cluster', current_cluster) return self.save(current_cluster)
def _create(self, user, cluster): cluster = self.setUserAccess(cluster, user=user, level=AccessType.ADMIN) group = { '_id': ObjectId(self.get_group_id()) } cluster = self.setGroupAccess(cluster, group, level=AccessType.ADMIN) # Add userId field to indicate ownership cluster['userId'] = user['_id'] self.save(cluster) send_status_notification('cluster', cluster) return cluster
def _create(self, user, cluster): cluster = self.setUserAccess(cluster, user=user, level=AccessType.ADMIN) group = { '_id': ObjectId(self.get_group_id()) } cluster = self.setGroupAccess(cluster, group, level=AccessType.ADMIN) # Add userId field to indicate ownership cluster['userId'] = user['_id'] self.save(cluster) send_status_notification('cluster', cluster) return cluster
def create(self, user, job): job['status'] = 'created' job['log'] = [] self.setUserAccess(job, user=user, level=AccessType.ADMIN) group = {'_id': ObjectId(self.get_group_id())} doc = self.setGroupAccess(job, group, level=AccessType.ADMIN) # Add the user id of the creator to indicate ownership job['userId'] = user['_id'] self.save(job) send_status_notification('job', job) return doc
def create(self, user, job): job["status"] = "created" job["log"] = [] self.setUserAccess(job, user=user, level=AccessType.ADMIN) group = {"_id": ObjectId(self.get_group_id())} doc = self.setGroupAccess(job, group, level=AccessType.ADMIN) # Add the user id of the creator to indicate ownership job["userId"] = user["_id"] self.save(job) send_status_notification("job", job) return doc
def update_state(self, user, taskflow_id): """ Update the state of the taskflow. This is called any time a task in the flow updates its state. """ taskflow = self.load(taskflow_id, level=AccessType.WRITE, user=user) # Use a 'update if current' strategy to update the taskflow state. This # should work provided we don't have high contention, if we start to # see high contention we will need to rethink this. new_status = self.status(user, taskflow) # We have nothing todo if taskflow['status'] == new_status: return query = { '_id': taskflow['_id'], 'status': taskflow['status'] } update = { '$set': {'status': new_status} } retries = 0 while True: update_result = self.update(query, update, multi=False) if update_result.modified_count > 0 or \ update_result.matched_count == 0: break if retries < MAX_RETRIES: retries += 1 else: raise Exception('Max retry count exceeded.') if taskflow['status'] != new_status: taskflow['status'] = new_status events.trigger('cumulus.taskflow.status_update', {'taskflow': taskflow}) send_status_notification('taskflow', taskflow)
def detach_complete(self, volume, params): # First remove from cluster user = getCurrentUser() cluster = self.model('cluster', 'cumulus').load(volume['clusterId'], user=user, level=AccessType.ADMIN) cluster.setdefault('volumes', []).remove(volume['_id']) del volume['clusterId'] for attr in ['path', 'msg']: try: del volume[attr] except KeyError: pass volume['status'] = VolumeState.AVAILABLE self.model('cluster', 'cumulus').save(cluster) self._model.save(volume) send_status_notification('volume', volume)
def update_state(self, user, taskflow_id): """ Update the state of the taskflow. This is called any time a task in the flow updates its state. """ taskflow = self.load(taskflow_id, level=AccessType.WRITE, user=user) # Use a 'update if current' strategy to update the taskflow state. This # should work provided we don't have high contention, if we start to # see high contention we will need to rethink this. new_status = self.status(user, taskflow) # We have nothing todo if taskflow['status'] == new_status: return query = { '_id': taskflow['_id'], 'status': taskflow['status'] } update = { '$set': {'status': new_status} } retries = 0 while True: update_result = self.update(query, update, multi=False) if update_result.modified_count > 0 or \ update_result.matched_count == 0: break if retries < MAX_RETRIES: retries += 1 else: raise Exception('Max retry count exceeded.') if taskflow['status'] != new_status: taskflow['status'] = new_status send_status_notification('taskflow', taskflow)
def detach_complete(self, volume, params): # First remove from cluster user = getCurrentUser() cluster = self.model('cluster', 'cumulus').load(volume['clusterId'], user=user, level=AccessType.ADMIN) cluster.setdefault('volumes', []).remove(volume['_id']) del volume['clusterId'] for attr in ['path', 'msg']: try: del volume[attr] except KeyError: pass volume['status'] = VolumeState.AVAILABLE self.model('cluster', 'cumulus').save(cluster) self._model.save(volume) send_status_notification('volume', volume)