@Test public void testHealthyInstance() { UUID instId = UUID.randomUUID(); UUID jobId = UUID.randomUUID(); InstanceInfo instance = mockInstanceInfo("foo", 1, 4096, jobId, InstanceStatus.StateEnum.RUNNING); JobDefinition job = mockJobWithSingleInstance("foo", 1, 4096); HealthCheckReport report = JobWatcherUtil.computeHealthCheckReport( Collections.singletonMap(jobId, job), Collections.singletonMap(instId, instance)); assertTrue(report.spuriousInstances().isEmpty()); assertTrue(report.instancesWithDifferentParameters().isEmpty()); assertTrue(report.instancesToStart().isEmpty()); }
static HealthCheckReport computeHealthCheckReport(Map<UUID, JobDefinition> jobs, Map<UUID, InstanceInfo> instances) { JobWatcherUtil.StateView v = JobWatcherUtil.computeState(jobs, instances); HealthCheckReport res = new HealthCheckReport(); for (Map.Entry<UUID, List<InstanceInfo>> e : v.jobInstances.entrySet()) { JobDefinition job = v.jobs.get(e.getKey()); if (job == null) { res.spuriousInstances().addAll(e.getValue()); continue; } Map<InstanceInfo, JobDefinitionDesiredstate> instanceState = new HashMap<>(); e.getValue().forEach(x -> instanceState.put(x, JobWatcherUtil.computeActualState(x))); List<JobDefinitionDesiredstate> desiredState = new ArrayList<>(job.getDesiredState()); List<InstanceInfo> healthyInstances = new ArrayList<>(); for (Map.Entry<InstanceInfo, JobDefinitionDesiredstate> entry : instanceState.entrySet()) { if (desiredState.contains(entry.getValue())) { desiredState.remove(entry.getValue()); healthyInstances.add(entry.getKey()); } } List<InstanceInfo> allInstances = e.getValue(); allInstances.removeAll(healthyInstances); res.instancesWithDifferentParameters().addAll(allInstances); if (!desiredState.isEmpty()) { res.instancesToStart().put( new ExtendedJobDefinition().uuid(e.getKey()) .definition(job), desiredState); } } return res; }
JobWatcherUtil { static HealthCheckReport computeHealthCheckReport(Map<UUID, JobDefinition> jobs, Map<UUID, InstanceInfo> instances) { JobWatcherUtil.StateView v = JobWatcherUtil.computeState(jobs, instances); HealthCheckReport res = new HealthCheckReport(); for (Map.Entry<UUID, List<InstanceInfo>> e : v.jobInstances.entrySet()) { JobDefinition job = v.jobs.get(e.getKey()); if (job == null) { res.spuriousInstances().addAll(e.getValue()); continue; } Map<InstanceInfo, JobDefinitionDesiredstate> instanceState = new HashMap<>(); e.getValue().forEach(x -> instanceState.put(x, JobWatcherUtil.computeActualState(x))); List<JobDefinitionDesiredstate> desiredState = new ArrayList<>(job.getDesiredState()); List<InstanceInfo> healthyInstances = new ArrayList<>(); for (Map.Entry<InstanceInfo, JobDefinitionDesiredstate> entry : instanceState.entrySet()) { if (desiredState.contains(entry.getValue())) { desiredState.remove(entry.getValue()); healthyInstances.add(entry.getKey()); } } List<InstanceInfo> allInstances = e.getValue(); allInstances.removeAll(healthyInstances); res.instancesWithDifferentParameters().addAll(allInstances); if (!desiredState.isEmpty()) { res.instancesToStart().put( new ExtendedJobDefinition().uuid(e.getKey()) .definition(job), desiredState); } } return res; } }
JobWatcherUtil { static HealthCheckReport computeHealthCheckReport(Map<UUID, JobDefinition> jobs, Map<UUID, InstanceInfo> instances) { JobWatcherUtil.StateView v = JobWatcherUtil.computeState(jobs, instances); HealthCheckReport res = new HealthCheckReport(); for (Map.Entry<UUID, List<InstanceInfo>> e : v.jobInstances.entrySet()) { JobDefinition job = v.jobs.get(e.getKey()); if (job == null) { res.spuriousInstances().addAll(e.getValue()); continue; } Map<InstanceInfo, JobDefinitionDesiredstate> instanceState = new HashMap<>(); e.getValue().forEach(x -> instanceState.put(x, JobWatcherUtil.computeActualState(x))); List<JobDefinitionDesiredstate> desiredState = new ArrayList<>(job.getDesiredState()); List<InstanceInfo> healthyInstances = new ArrayList<>(); for (Map.Entry<InstanceInfo, JobDefinitionDesiredstate> entry : instanceState.entrySet()) { if (desiredState.contains(entry.getValue())) { desiredState.remove(entry.getValue()); healthyInstances.add(entry.getKey()); } } List<InstanceInfo> allInstances = e.getValue(); allInstances.removeAll(healthyInstances); res.instancesWithDifferentParameters().addAll(allInstances); if (!desiredState.isEmpty()) { res.instancesToStart().put( new ExtendedJobDefinition().uuid(e.getKey()) .definition(job), desiredState); } } return res; } private  JobWatcherUtil(); }
JobWatcherUtil { static HealthCheckReport computeHealthCheckReport(Map<UUID, JobDefinition> jobs, Map<UUID, InstanceInfo> instances) { JobWatcherUtil.StateView v = JobWatcherUtil.computeState(jobs, instances); HealthCheckReport res = new HealthCheckReport(); for (Map.Entry<UUID, List<InstanceInfo>> e : v.jobInstances.entrySet()) { JobDefinition job = v.jobs.get(e.getKey()); if (job == null) { res.spuriousInstances().addAll(e.getValue()); continue; } Map<InstanceInfo, JobDefinitionDesiredstate> instanceState = new HashMap<>(); e.getValue().forEach(x -> instanceState.put(x, JobWatcherUtil.computeActualState(x))); List<JobDefinitionDesiredstate> desiredState = new ArrayList<>(job.getDesiredState()); List<InstanceInfo> healthyInstances = new ArrayList<>(); for (Map.Entry<InstanceInfo, JobDefinitionDesiredstate> entry : instanceState.entrySet()) { if (desiredState.contains(entry.getValue())) { desiredState.remove(entry.getValue()); healthyInstances.add(entry.getKey()); } } List<InstanceInfo> allInstances = e.getValue(); allInstances.removeAll(healthyInstances); res.instancesWithDifferentParameters().addAll(allInstances); if (!desiredState.isEmpty()) { res.instancesToStart().put( new ExtendedJobDefinition().uuid(e.getKey()) .definition(job), desiredState); } } return res; } private  JobWatcherUtil();  }
JobWatcherUtil { static HealthCheckReport computeHealthCheckReport(Map<UUID, JobDefinition> jobs, Map<UUID, InstanceInfo> instances) { JobWatcherUtil.StateView v = JobWatcherUtil.computeState(jobs, instances); HealthCheckReport res = new HealthCheckReport(); for (Map.Entry<UUID, List<InstanceInfo>> e : v.jobInstances.entrySet()) { JobDefinition job = v.jobs.get(e.getKey()); if (job == null) { res.spuriousInstances().addAll(e.getValue()); continue; } Map<InstanceInfo, JobDefinitionDesiredstate> instanceState = new HashMap<>(); e.getValue().forEach(x -> instanceState.put(x, JobWatcherUtil.computeActualState(x))); List<JobDefinitionDesiredstate> desiredState = new ArrayList<>(job.getDesiredState()); List<InstanceInfo> healthyInstances = new ArrayList<>(); for (Map.Entry<InstanceInfo, JobDefinitionDesiredstate> entry : instanceState.entrySet()) { if (desiredState.contains(entry.getValue())) { desiredState.remove(entry.getValue()); healthyInstances.add(entry.getKey()); } } List<InstanceInfo> allInstances = e.getValue(); allInstances.removeAll(healthyInstances); res.instancesWithDifferentParameters().addAll(allInstances); if (!desiredState.isEmpty()) { res.instancesToStart().put( new ExtendedJobDefinition().uuid(e.getKey()) .definition(job), desiredState); } } return res; } private  JobWatcherUtil();   }