Java Code Examples for org.apache.flink.runtime.jobmaster.JobMasterId#fromUuidOrNull()

The following examples show how to use org.apache.flink.runtime.jobmaster.JobMasterId#fromUuidOrNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultJobLeaderService.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyLeaderAddress(@Nullable final String leaderAddress, @Nullable final UUID leaderId) {
	Optional<JobMasterId> jobManagerLostLeadership = Optional.empty();

	synchronized (lock) {
		if (stopped) {
			LOG.debug("{}'s leader retrieval listener reported a new leader for job {}. " +
				"However, the service is no longer running.", DefaultJobLeaderService.class.getSimpleName(), jobId);
		} else {
			final JobMasterId jobMasterId = JobMasterId.fromUuidOrNull(leaderId);

			LOG.debug("New leader information for job {}. Address: {}, leader id: {}.",
				jobId, leaderAddress, jobMasterId);

			if (leaderAddress == null || leaderAddress.isEmpty()) {
				// the leader lost leadership but there is no other leader yet.
				jobManagerLostLeadership = Optional.ofNullable(currentJobMasterId);
				closeRpcConnection();
			} else {
				// check whether we are already connecting to this leader
				if (Objects.equals(jobMasterId, currentJobMasterId)) {
					LOG.debug("Ongoing attempt to connect to leader of job {}. Ignoring duplicate leader information.", jobId);
				} else {
					closeRpcConnection();
					openRpcConnectionTo(leaderAddress, jobMasterId);
				}
			}
		}
	}

	// send callbacks outside of the lock scope
	jobManagerLostLeadership.ifPresent(oldJobMasterId -> jobLeaderListener.jobManagerLostLeadership(jobId, oldJobMasterId));
}
 
Example 2
Source File: JobLeaderService.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void notifyLeaderAddress(final @Nullable String leaderAddress, final @Nullable UUID leaderId) {
	if (stopped) {
		LOG.debug("{}'s leader retrieval listener reported a new leader for job {}. " +
			"However, the service is no longer running.", JobLeaderService.class.getSimpleName(), jobId);
	} else {
		final JobMasterId jobMasterId = JobMasterId.fromUuidOrNull(leaderId);

		LOG.debug("New leader information for job {}. Address: {}, leader id: {}.",
			jobId, leaderAddress, jobMasterId);

		if (leaderAddress == null || leaderAddress.isEmpty()) {
			// the leader lost leadership but there is no other leader yet.
			if (rpcConnection != null) {
				rpcConnection.close();
			}

			jobLeaderListener.jobManagerLostLeadership(jobId, currentJobMasterId);

			currentJobMasterId = jobMasterId;
		} else {
			currentJobMasterId = jobMasterId;

			if (rpcConnection != null) {
				// check if we are already trying to connect to this leader
				if (!Objects.equals(jobMasterId, rpcConnection.getTargetLeaderId())) {
					rpcConnection.close();

					rpcConnection = new JobManagerRegisteredRpcConnection(
						LOG,
						leaderAddress,
						jobMasterId,
						rpcService.getExecutor());
				}
			} else {
				rpcConnection = new JobManagerRegisteredRpcConnection(
					LOG,
					leaderAddress,
					jobMasterId,
					rpcService.getExecutor());
			}

			// double check for a concurrent stop operation
			if (stopped) {
				rpcConnection.close();
			} else {
				LOG.info("Try to register at job manager {} with leader id {}.", leaderAddress, leaderId);
				rpcConnection.start();
			}
		}
	}
}
 
Example 3
Source File: JobLeaderService.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void notifyLeaderAddress(final @Nullable String leaderAddress, final @Nullable UUID leaderId) {
	if (stopped) {
		LOG.debug("{}'s leader retrieval listener reported a new leader for job {}. " +
			"However, the service is no longer running.", JobLeaderService.class.getSimpleName(), jobId);
	} else {
		final JobMasterId jobMasterId = JobMasterId.fromUuidOrNull(leaderId);

		LOG.debug("New leader information for job {}. Address: {}, leader id: {}.",
			jobId, leaderAddress, jobMasterId);

		if (leaderAddress == null || leaderAddress.isEmpty()) {
			// the leader lost leadership but there is no other leader yet.
			if (rpcConnection != null) {
				rpcConnection.close();
			}

			jobLeaderListener.jobManagerLostLeadership(jobId, currentJobMasterId);

			currentJobMasterId = jobMasterId;
		} else {
			currentJobMasterId = jobMasterId;

			if (rpcConnection != null) {
				// check if we are already trying to connect to this leader
				if (!Objects.equals(jobMasterId, rpcConnection.getTargetLeaderId())) {
					rpcConnection.close();

					rpcConnection = new JobManagerRegisteredRpcConnection(
						LOG,
						leaderAddress,
						jobMasterId,
						rpcService.getExecutor());
				}
			} else {
				rpcConnection = new JobManagerRegisteredRpcConnection(
					LOG,
					leaderAddress,
					jobMasterId,
					rpcService.getExecutor());
			}

			// double check for a concurrent stop operation
			if (stopped) {
				rpcConnection.close();
			} else {
				LOG.info("Try to register at job manager {} with leader id {}.", leaderAddress, leaderId);
				rpcConnection.start();
			}
		}
	}
}