Completes the process of handing off a work unit from one node to the current one.
Attempts to establish a final claim to the node handed off to me in ZooKeeper, and
repeats execution of the task every two seconds until it is complete.
545109
public void finishHandoff(final String workUnit) throws InterruptedException
    {
        String unitId = cluster.workUnitMap.get(workUnit);
        LOG.info("Handoff of {} to me acknowledged. Deleting claim ZNode for {} and waiting for {} to shutdown work.",
                workUnit, workUnit,
                ((unitId == null) ? "(None)" : unitId));

        final String path = cluster.workUnitClaimPath(workUnit);

        Stat stat = ZKUtils.exists(cluster.zk, path, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                // Don't really care about the type of event here - call unconditionally to clean up state
                completeHandoff(workUnit, path);
            }
        });
        // Unlikely that peer will have already deleted znode, but handle it regardless
        if (stat == null) {
            LOG.warn("Peer already deleted znode of {}", workUnit);
            completeHandoff(workUnit, path);
        }
    }
66589
@Override
  public void completing(DelegateExecution execution, DelegateExecution subProcessInstance) throws Exception {
    if (activityBehaviorInstance == null) {
      activityBehaviorInstance = getActivityBehaviorInstance();
    }

    if (activityBehaviorInstance instanceof SubProcessActivityBehavior) {
      ((SubProcessActivityBehavior) activityBehaviorInstance).completing(execution, subProcessInstance);
    } else {
      throw new ActivitiException("completing() can only be called on a " + SubProcessActivityBehavior.class.getName() + " instance");
    }
  }
747481
void vertexFinished() {
		assertRunningInJobMasterMainThread();
		final int numFinished = verticesFinished.incrementAndGet();
		if (numFinished == numVerticesTotal) {
			// done :-)

			// check whether we are still in "RUNNING" and trigger the final cleanup
			if (state == JobStatus.RUNNING) {
				// we do the final cleanup in the I/O executor, because it may involve
				// some heavier work

				try {
					for (ExecutionJobVertex ejv : verticesInCreationOrder) {
						ejv.getJobVertex().finalizeOnMaster(getUserClassLoader());
					}
				}
				catch (Throwable t) {
					ExceptionUtils.rethrowIfFatalError(t);
					failGlobal(new Exception("Failed to finalize execution on master", t));
					return;
				}

				// if we do not make this state transition, then a concurrent
				// cancellation or failure happened
				if (transitionState(JobStatus.RUNNING, JobStatus.FINISHED)) {
					onTerminalState(JobStatus.FINISHED);
				}
			}
		}
	}
596812
private Runnable createStopTask() {
    return new Runnable() {
      @Override
      public void run() {
        try {
          // Close the ZK connection in this task will make sure if there is ZK connection created
          // after doStop() was called but before this task has been executed is also closed.
          // It is possible to happen when the following sequence happens:
          //
          // 1. session expired, hence the expired event is triggered
          // 2. The reconnect task executed. With Service.state() == RUNNING, it creates a new ZK client
          // 3. Service.stop() gets called, Service.state() changed to STOPPING
          // 4. The new ZK client created from the reconnect thread update the zooKeeper with the new one
          closeZooKeeper(zooKeeper.getAndSet(null));
          notifyStopped();
        } catch (Exception e) {
          notifyFailed(e);
        }
      }
    };
  }
1289809
def _complete_task(self, task_name, **kwargs):
        

        logger.debug('Job {0} marking task {1} as completed'.format(self.name, task_name))
        self.run_log['tasks'][task_name] = kwargs

        for node in self.downstream(task_name, self.snapshot):
            self._start_if_ready(node)

        try:
            self.backend.acquire_lock()
            self._commit_run_log()
        except:
            logger.exception("Error in handling events.")
        finally:
            self.backend.release_lock()

        if kwargs.get('success', None) == False:
            task = self.tasks[task_name]
            try:
                self.backend.acquire_lock()
                if self.event_handler:
                    self.event_handler.emit('task_failed',
                                            task._serialize(include_run_logs=True))
            except:
                logger.exception("Error in handling events.")
            finally:
                self.backend.release_lock()

        self._on_completion()
1235453
def handle_wf_finalization(self):
        
        if ((not self.current.flow_enabled or (
            self.current.task_type.startswith('End') and not self.are_we_in_subprocess())) and
                    'token' in self.current.output):
            del self.current.output['token']
835119
public synchronized void finish() {
    if (!this.isInitialized()) {
      throw new IllegalStateException("Torrent not yet initialized!");
    }

    if (!this.isComplete()) {
      throw new IllegalStateException("Torrent download is not complete!");
    }

    eventDispatcher.multicaster().downloadComplete();
    setClientState(ClientState.SEEDING);
  }
778251
def _handle_end_node(self):
        
        self._result.append(Node(result=self._result, **self._curr))
        self._curr = {}
580062
def end_workunit(self, workunit):
    """"""

    additional_data = {
      'outcome': workunit.outcome_string(workunit.outcome()),
      'end_time': workunit.end_time,
      'unaccounted_time': workunit.unaccounted_time(),
    }

    root_id = str(workunit.root().id)

    # We update the last workunit in the stack, which is always the
    # youngest workunit currently open, and then pop it off. The
    # last workunit serves as a pointer to the child workunit under
    # it's parent (the parent of the youngest workunit currently
    # open is always the one immediately above it in the stack).
    self._root_id_to_workunit_stack[root_id][-1].update(additional_data)
    self._root_id_to_workunit_stack[root_id].pop()
116208
public void finish() throws IOException {
		boolean success = false;

		try {
			checkInProduceState();

			for (ResultSubpartition subpartition : subpartitions) {
				subpartition.finish();
			}

			success = true;
		}
		finally {
			if (success) {
				isFinished = true;

				notifyPipelinedConsumers();
			}
		}
	}
1048840
def mark_done(self, node_id):
        
        with self.lock:
            self.in_progress.remove(node_id)
            self.graph.remove_node(node_id)
            self._find_new_additions()
            self.inner.task_done()
1046261
@Subscribe
    public void complete(ReplicationCompleted rc) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                if (mListener != null) {
                    mListener.replicationComplete();
                }
            }
        });
    }
1149356
int claimResource(ZooKeeper zookeeper, String poolNode, int poolSize)
            throws KeeperException, InterruptedException {

        logger.debug("Trying to claim a resource.");
        List<String> claimedResources = zookeeper.getChildren(poolNode, false);
        if (claimedResources.size() >= poolSize) {
            logger.debug("No resources available at the moment (pool size: {}), waiting.", poolSize);
            // No resources available. Wait for a resource to become available.
            final CountDownLatch latch = new CountDownLatch(1);
            zookeeper.getChildren(poolNode, event -> latch.countDown());
            latch.await();
            return claimResource(zookeeper, poolNode, poolSize);
        }

        // Try to claim an available resource.
        for (int i = 0; i < poolSize; i++) {
            String resourcePath = Integer.toString(i);
            if (!claimedResources.contains(resourcePath)) {
                String node;
                try {
                    logger.debug("Trying to claim seemingly available resource {}.", resourcePath);
                    node = zookeeper.create(
                            poolNode + "/" + resourcePath,
                            new byte[0],
                            ZooDefs.Ids.OPEN_ACL_UNSAFE,
                            CreateMode.EPHEMERAL
                    );
                } catch (KeeperException e) {
                    if (e.code() == KeeperException.Code.NODEEXISTS) {
                        // Failed to claim this resource for some reason.
                        continue;
                    } else {
                        // Unexpected failure.
                        throw e;
                    }
                }

                zookeeper.exists(node, event -> {
                    if (event.getType() == EventType.NodeDeleted) {
                        // Invalidate our claim when the node is deleted by some other process.
                        logger.debug("Resource-claim node unexpectedly deleted ({})", resource);
                        close(true);
                    }
                });

                logger.debug("Successfully claimed resource {}.", resourcePath);
                return i;
            }
        }

        return claimResource(zookeeper, poolNode, poolSize);
    }
976389
def worker_complete():
    '''  '''
    if not 'uniqueId' in request.args:
        resp = {"status": "bad request"}
        return jsonify(**resp)
    else:
        unique_id = request.args['uniqueId']
        app.logger.info("Completed experiment %s" % unique_id)
        try:
            user = Participant.query.\
                filter(Participant.uniqueid == unique_id).one()
            user.status = COMPLETED
            user.endhit = datetime.datetime.now()
            db_session.add(user)
            db_session.commit()
            status = "success"
        except exc.SQLAlchemyError:
            status = "database error"
        resp = {"status" : status}
        return jsonify(**resp)
448516
@PostConstruct
    public void runSetup() throws SetupException {
        HAConfiguration.ZookeeperProperties zookeeperProperties = HAConfiguration.getZookeeperProperties(configuration);
        InterProcessMutex lock = curatorFactory.lockInstance(zookeeperProperties.getZkRoot());
        try {
            LOG.info("Trying to acquire lock for running setup.");
            lock.acquire();
            LOG.info("Acquired lock for running setup.");
            handleSetupInProgress(configuration, zookeeperProperties);
            for (SetupStep step : setupSteps) {
                LOG.info("Running setup step: {}", step);
                step.run();
            }
            clearSetupInProgress(zookeeperProperties);
        } catch (SetupException se) {
            LOG.error("Got setup exception while trying to setup", se);
            throw se;
        } catch (Throwable e) {
            LOG.error("Error running setup steps", e);
            throw new SetupException("Error running setup steps", e);
        } finally {
            releaseLock(lock);
            curatorFactory.close();
        }
    }
431195
public boolean leave() throws KeeperException, InterruptedException{
		zooKeeper.delete(rootPath + "/" + name, 0);
		while (true) {
			synchronized (mutex) {
				List<String> list = zooKeeper.getChildren(rootPath, true);
				if (list.size() > 0) {
					mutex.wait();
				} else {
					return true;
				}
			}
		}
	}
195472
private void complete(Object value) {
        future.complete(value);
        if (context.invocationRegistry.deregister(this) && taskDoneCallback != null) {
            context.asyncExecutor.execute(taskDoneCallback);
        }
    }