@Before public void setUp() throws Exception { // make zookeeper interfaces curator = zk().curatorWithSuperAuth(); final ZooKeeperClientProvider zkcp = new ZooKeeperClientProvider( new DefaultZooKeeperClient(curator), ZooKeeperModelReporter.noop()); final List<EventSender> eventSenders = Collections.emptyList(); zkMasterModel = new ZooKeeperMasterModel(zkcp, getClass().getName(), eventSenders, ""); startDefaultMaster(); agent = startDefaultAgent(TEST_HOST); client = defaultClient(); awaitHostRegistered(client, TEST_HOST, LONG_WAIT_SECONDS, SECONDS); }
private ZooKeeperClient client(final String tag) { return provider.get("persistent_directory_" + tag); }
@Test public void testRemoveJobDeletesHistory() throws Exception { startDefaultAgent(testHost()); awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS); final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND); deployJob(jobId, testHost()); awaitJobState( defaultClient(), testHost(), jobId, TaskStatus.State.RUNNING, LONG_WAIT_SECONDS, SECONDS); undeployJob(jobId, testHost()); awaitJobUndeployed(defaultClient(), testHost(), jobId, LONG_WAIT_SECONDS, SECONDS); final ZooKeeperClient zkClient = new ZooKeeperClientProvider( new DefaultZooKeeperClient(zk().curatorWithSuperAuth()), ZooKeeperModelReporter.noop()) .get("test-client"); // Check that there's some history events assertNotNull(zkClient.stat(Paths.historyJob(jobId))); // Remove job final JobDeleteResponse response = defaultClient().deleteJob(jobId).get(WAIT_TIMEOUT_SECONDS, SECONDS); assertEquals(JobDeleteResponse.Status.OK, response.getStatus()); // Verify that history is gone assertNull(zkClient.stat(Paths.historyJob(jobId))); } }
final ZooKeeperModelReporter modelReporter = new ZooKeeperModelReporter(metrics.getZooKeeperMetrics()); final ZooKeeperClientProvider zkClientProvider = new ZooKeeperClientProvider( zooKeeperClient, modelReporter); new JobHistoryReaper(model, zkClientProvider.get("jobHistoryReaper"))); } else { log.info("Reaping of orphaned jobs disabled");
/** * Returns the job configuration for the job specified by {@code id} as a * {@link Job} object. A return value of null indicates the job doesn't exist. */ @Override public Job getJob(final JobId id) { log.debug("getting job: {}", id); final ZooKeeperClient client = provider.get("getJobId"); return getJob(client, id); }
final ZooKeeperClientProvider zkClientProvider = new ZooKeeperClientProvider( zooKeeperClient, modelReporter);
@Override public AgentInfo getAgentInfo(final String host) { return getAgentInfo(provider.get("getAgentInfo"), host); }
final ZooKeeperClientProvider zkClientProvider = new ZooKeeperClientProvider( zooKeeperClient, modelReporter); final KafkaClientProvider kafkaClientProvider = new KafkaClientProvider(
/** * Undoes the effect of {@link ZooKeeperMasterModel#registerHost(String, String)}. Cleans up * any leftover host-related things. */ @Override public void deregisterHost(final String host) throws HostNotFoundException, HostStillInUseException { final ZooKeeperClient client = provider.get("deregisterHost"); ZooKeeperRegistrarUtil.deregisterHost(client, host); }
final ZooKeeperModelReporter modelReporter = new ZooKeeperModelReporter( riemannFacade, metrics.getZooKeeperMetrics()); final ZooKeeperClientProvider zkClientProvider = new ZooKeeperClientProvider( zooKeeperClient, modelReporter); final KafkaClientProvider kafkaClientProvider = new KafkaClientProvider(
/** * Creates a config entry within the specified agent to un/deploy a job, or more generally, change * the deployment status according to the {@code Goal} value in {@link Deployment}. */ @Override public void deployJob(final String host, final Deployment deployment, final String token) throws JobDoesNotExistException, JobAlreadyDeployedException, HostNotFoundException, JobPortAllocationConflictException, TokenVerificationException { final ZooKeeperClient client = provider.get("deployJob"); deployJobRetry(client, host, deployment, 0, token); }
@Override public DeploymentGroup getDeploymentGroup(final String name) throws DeploymentGroupDoesNotExistException { log.debug("getting deployment-group: {}", name); final ZooKeeperClient client = provider.get("getDeploymentGroup"); return getDeploymentGroup(client, name); }
@Override public Map<String, String> getHostLabels(final String host) { final ZooKeeperClient client = provider.get("getHostStatus"); if (!ZooKeeperRegistrarUtil.isHostRegistered(client, host)) { return emptyMap(); } final Map<String, String> labels = getLabels(client, host); return labels == null ? emptyMap() : labels; }
@Override public boolean isHostUp(final String host) { final ZooKeeperClient client = provider.get("isHostUp"); return ZooKeeperRegistrarUtil.isHostRegistered(client, host) && checkHostUp(client, host); }
/** * Returns a list of the hosts/agents that have been registered. */ @Override public List<String> listHosts() { try { // TODO (dano): only return hosts whose agents completed registration (i.e. has id nodes) return provider.get("listHosts").getChildren(Paths.configHosts()); } catch (KeeperException.NoNodeException e) { return emptyList(); } catch (KeeperException e) { throw new HeliosRuntimeException("listing hosts failed", e); } }
@Override public List<String> getDeploymentGroupHosts(final String name) throws DeploymentGroupDoesNotExistException { log.debug("getting deployment group hosts: {}", name); final ZooKeeperClient client = provider.get("getDeploymentGroupHosts"); final DeploymentGroup deploymentGroup = getDeploymentGroup(client, name); if (deploymentGroup == null) { throw new DeploymentGroupDoesNotExistException(name); } return getHosts(client, Paths.statusDeploymentGroupHosts(name)); }
/** * Registers a host into ZooKeeper. The {@code id} is initially generated randomly by the Agent * and persisted on disk. This way, in the event that you have two agents attempting to register * with the same value of @{code host}, the first one will win. */ @Override public void registerHost(final String host, final String id) { final ZooKeeperClient client = provider.get("registerHost"); try { ZooKeeperRegistrarUtil.registerHost(client, Paths.configHostId(host), host, id); } catch (Exception e) { throw new HeliosRuntimeException("registering host " + host + " failed", e); } }
/** * Returns a list of the host names of the currently running masters. */ @Override public List<String> getRunningMasters() { final ZooKeeperClient client = provider.get("getRunningMasters"); try { final List<String> masters = client.getChildren(Paths.statusMaster()); final ImmutableList.Builder<String> upMasters = ImmutableList.builder(); for (final String master : masters) { if (client.exists(Paths.statusMasterUp(master)) != null) { upMasters.add(master); } } return upMasters.build(); } catch (KeeperException e) { throw new HeliosRuntimeException("listing masters failed", e); } }
throw new JobDoesNotExistException(jobId); final ZooKeeperClient client = provider.get("getJobHistory"); final List<String> hosts;
log.debug("getting deployment groups"); final String folder = Paths.configDeploymentGroups(); final ZooKeeperClient client = provider.get("getDeploymentGroups"); try { final List<String> names;