@Test public void testValidJob() throws Exception { when(jobOperations.getJob(JOB_ID)).thenReturn(Optional.of(Job.<ServiceJobExt>newBuilder() .withId(JOB_ID) .withStatus(JobStatus.newBuilder() .withState(JobState.Accepted) .build()) .withJobDescriptor(JobDescriptor.<ServiceJobExt>newBuilder() .withExtensions(ServiceJobExt.newBuilder().build()) .withContainer(Container.newBuilder() .withImage(Image.newBuilder().build()) .withContainerResources(ContainerResources.newBuilder() .withAllocateIP(true) .build()) .build()) .build()) .build())); assertThatCode(() -> loadBalancerValidator.validateJobId(JOB_ID)).doesNotThrowAnyException(); }
@Override public void validateJobId(String jobId) throws LoadBalancerException, JobManagerException { Job job = v3JobOperations.getJob(jobId).orElseThrow(() -> JobManagerException.v3JobNotFound(jobId)); JobState state = job.getStatus().getState(); if (state != JobState.Accepted) { throw JobManagerException.unexpectedJobState(job, JobState.Accepted); } JobDescriptor.JobDescriptorExt extensions = job.getJobDescriptor().getExtensions(); if (!(extensions instanceof ServiceJobExt)) { throw JobManagerException.notServiceJob(jobId); } int maxLoadBalancers = loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob(); int numLoadBalancers = loadBalancerStore.getNumLoadBalancersForJob(jobId); if (numLoadBalancers > maxLoadBalancers) { throw LoadBalancerException.jobMaxLoadBalancers(jobId, numLoadBalancers, maxLoadBalancers); } }
DefaultLoadBalancerJobValidator implements LoadBalancerJobValidator { @Override public void validateJobId(String jobId) throws LoadBalancerException, JobManagerException { Job job = v3JobOperations.getJob(jobId).orElseThrow(() -> JobManagerException.v3JobNotFound(jobId)); JobState state = job.getStatus().getState(); if (state != JobState.Accepted) { throw JobManagerException.unexpectedJobState(job, JobState.Accepted); } JobDescriptor.JobDescriptorExt extensions = job.getJobDescriptor().getExtensions(); if (!(extensions instanceof ServiceJobExt)) { throw JobManagerException.notServiceJob(jobId); } int maxLoadBalancers = loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob(); int numLoadBalancers = loadBalancerStore.getNumLoadBalancersForJob(jobId); if (numLoadBalancers > maxLoadBalancers) { throw LoadBalancerException.jobMaxLoadBalancers(jobId, numLoadBalancers, maxLoadBalancers); } } }
DefaultLoadBalancerJobValidator implements LoadBalancerJobValidator { @Override public void validateJobId(String jobId) throws LoadBalancerException, JobManagerException { Job job = v3JobOperations.getJob(jobId).orElseThrow(() -> JobManagerException.v3JobNotFound(jobId)); JobState state = job.getStatus().getState(); if (state != JobState.Accepted) { throw JobManagerException.unexpectedJobState(job, JobState.Accepted); } JobDescriptor.JobDescriptorExt extensions = job.getJobDescriptor().getExtensions(); if (!(extensions instanceof ServiceJobExt)) { throw JobManagerException.notServiceJob(jobId); } int maxLoadBalancers = loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob(); int numLoadBalancers = loadBalancerStore.getNumLoadBalancersForJob(jobId); if (numLoadBalancers > maxLoadBalancers) { throw LoadBalancerException.jobMaxLoadBalancers(jobId, numLoadBalancers, maxLoadBalancers); } } @Inject  DefaultLoadBalancerJobValidator(V3JobOperations v3JobOperations,
                                           LoadBalancerStore loadBalancerStore,
                                           LoadBalancerValidationConfiguration loadBalancerValidationConfiguration); }
DefaultLoadBalancerJobValidator implements LoadBalancerJobValidator { @Override public void validateJobId(String jobId) throws LoadBalancerException, JobManagerException { Job job = v3JobOperations.getJob(jobId).orElseThrow(() -> JobManagerException.v3JobNotFound(jobId)); JobState state = job.getStatus().getState(); if (state != JobState.Accepted) { throw JobManagerException.unexpectedJobState(job, JobState.Accepted); } JobDescriptor.JobDescriptorExt extensions = job.getJobDescriptor().getExtensions(); if (!(extensions instanceof ServiceJobExt)) { throw JobManagerException.notServiceJob(jobId); } int maxLoadBalancers = loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob(); int numLoadBalancers = loadBalancerStore.getNumLoadBalancersForJob(jobId); if (numLoadBalancers > maxLoadBalancers) { throw LoadBalancerException.jobMaxLoadBalancers(jobId, numLoadBalancers, maxLoadBalancers); } } @Inject  DefaultLoadBalancerJobValidator(V3JobOperations v3JobOperations,
                                           LoadBalancerStore loadBalancerStore,
                                           LoadBalancerValidationConfiguration loadBalancerValidationConfiguration); @Override void validateJobId(String jobId); }
DefaultLoadBalancerJobValidator implements LoadBalancerJobValidator { @Override public void validateJobId(String jobId) throws LoadBalancerException, JobManagerException { Job job = v3JobOperations.getJob(jobId).orElseThrow(() -> JobManagerException.v3JobNotFound(jobId)); JobState state = job.getStatus().getState(); if (state != JobState.Accepted) { throw JobManagerException.unexpectedJobState(job, JobState.Accepted); } JobDescriptor.JobDescriptorExt extensions = job.getJobDescriptor().getExtensions(); if (!(extensions instanceof ServiceJobExt)) { throw JobManagerException.notServiceJob(jobId); } int maxLoadBalancers = loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob(); int numLoadBalancers = loadBalancerStore.getNumLoadBalancersForJob(jobId); if (numLoadBalancers > maxLoadBalancers) { throw LoadBalancerException.jobMaxLoadBalancers(jobId, numLoadBalancers, maxLoadBalancers); } } @Inject  DefaultLoadBalancerJobValidator(V3JobOperations v3JobOperations,
                                           LoadBalancerStore loadBalancerStore,
                                           LoadBalancerValidationConfiguration loadBalancerValidationConfiguration); @Override void validateJobId(String jobId);  }