public ResourceConfigs toResourceConfigs() { final ResourceConfigs resourceConfigs = new ResourceConfigs(); for (Resource resource : this) { resourceConfigs.add(new ResourceConfig(resource.getName())); } return resourceConfigs; } }
public static ResourceConfigs resources(String... names) { ResourceConfigs resourceConfigs = new ResourceConfigs(); for (String name : names) { resourceConfigs.add(new ResourceConfig(name)); } return resourceConfigs; } }
@Test public void shouldGetAllResourcesNames() { ResourceConfigs resourceConfigs = new ResourceConfigs(); resourceConfigs.add(new ResourceConfig("Eoo")); resourceConfigs.add(new ResourceConfig("Poo")); List<String> names = new ArrayList<>(); names.add("Eoo"); names.add("Poo"); List<String> resourceNames = resourceConfigs.resourceNames(); assertThat(resourceNames, is(names)); }
@Test public void shouldFindAllAgentResources() { cruiseConfig.agents().add(new AgentConfig("uuid", "host1", "127.0.0.1", new ResourceConfigs("from-agent"))); assertThat(cruiseConfig.getAllResources(), hasItem(new ResourceConfig("from-agent"))); }
public static JobConfigs jobConfigs(String... buildNames) { JobConfigs jobConfigs = new JobConfigs(); for (String buildName : buildNames) { jobConfigs.add(new JobConfig(new CaseInsensitiveString(buildName), new ResourceConfigs(), new ArtifactConfigs())); } return jobConfigs; }
public static AgentInstance agentWithConfigErrors() { ResourceConfig resourceConfig1 = new ResourceConfig("foo%"); ResourceConfig resourceConfig2 = new ResourceConfig("bar$"); AgentConfig agentConfig = new AgentConfig("uuid", "host", "IP", new ResourceConfigs(resourceConfig1, resourceConfig2)); agentConfig.validateTree(ConfigSaveValidationContext.forChain(new BasicCruiseConfig())); return AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class)); } }
@Test public void shouldNotMatchJobPlanIfTheAgentIsElasticAndJobHasResourcesDefined() { AgentConfig agentConfig = new AgentConfig("uuid", "hostname", "11.1.1.1", new ResourceConfigs(new ResourceConfig("r1"))); agentConfig.setElasticAgentId("elastic-agent-id-1"); String elasticPluginId = "elastic-plugin-id-1"; agentConfig.setElasticPluginId(elasticPluginId); AgentInstance agentInstance = new AgentInstance(agentConfig, REMOTE, mock(SystemEnvironment.class), null); DefaultJobPlan jobPlan1 = new DefaultJobPlan(); jobPlan1.setResources(asList(new Resource("r1"))); List<JobPlan> jobPlans = asList(jobPlan1, new DefaultJobPlan()); assertThat(agentInstance.firstMatching(jobPlans), is(nullValue())); }
public static JobConfigs withBuildPlans(String... jobConfigNames) { JobConfigs jobConfigs = new JobConfigs(); for (String planName : jobConfigNames) { jobConfigs.add(new JobConfig(new CaseInsensitiveString(planName), new ResourceConfigs(), new ArtifactConfigs())); } return jobConfigs; }
@Test public void shouldNotBeAbleToAddResourceWithWhiteSpaceAsName() { ResourceConfigs actual = new ResourceConfigs(); actual.add(new ResourceConfig(" ")); assertThat(actual.size(), is(0)); }
@Test public void shouldCompareBasedOnResourceListItHas() { ResourceConfigs resourceConfigsA = new ResourceConfigs(); ResourceConfigs resourceConfigsB = new ResourceConfigs(); resourceConfigsA.add(new ResourceConfig("xyz")); resourceConfigsA.add(new ResourceConfig("aaa")); resourceConfigsB.add(new ResourceConfig("xyz")); resourceConfigsB.add(new ResourceConfig("bbb")); assertThat(resourceConfigsA.compareTo(resourceConfigsB), is(org.hamcrest.Matchers.lessThan(0))); assertThat(resourceConfigsB.compareTo(resourceConfigsA), is(greaterThan(0))); }
@Test public void shouldClearAndSetPrimitiveAttributes() { ResourceConfigs resourceConfigs = new ResourceConfigs(); String csv = "a, b, c,d "; resourceConfigs.add(new ResourceConfig("old_resource")); assertThat(resourceConfigs.size(), is(1)); resourceConfigs.importFromCsv(csv); assertThat(resourceConfigs.size(), is(4)); assertThat(resourceConfigs.exportToCsv(), is("a, b, c, d, ")); }
@Test public void shouldTrimResourceNames() { ResourceConfigs resourceConfigs = new ResourceConfigs(); resourceConfigs.add(new ResourceConfig("foo")); resourceConfigs.add(new ResourceConfig("foo ")); assertThat(resourceConfigs.size(), is(1)); ResourceConfigs newResourceConfigs = new ResourceConfigs(); newResourceConfigs.add(new ResourceConfig("foo ")); newResourceConfigs.add(new ResourceConfig("foo ")); assertThat(newResourceConfigs.size(), is(1)); }
@Test public void shouldIgnoreCaseNamesOfResources() { ResourceConfigs resourceConfigs = new ResourceConfigs(); resourceConfigs.add(new ResourceConfig("Eoo")); resourceConfigs.add(new ResourceConfig("eoo")); assertThat(resourceConfigs.size(), is(1)); }
@Test public void shouldNotAllowBlankNames() { ResourceConfigs resourceConfigs = new ResourceConfigs(); resourceConfigs.add(new ResourceConfig("")); assertThat(resourceConfigs.size(), is(0)); resourceConfigs.add(new ResourceConfig(" ")); assertThat(resourceConfigs.size(), is(0)); }
@Test public void shouldFindAllAgentsIfNoResourcesAreSpecified() throws Exception { AgentConfig linux = agent("uuid1", "linux"); AgentConfig windows = agent("uuid2", "windows"); Agents matchingAgents = new Agents(linux, windows); DefaultSchedulingContext context = new DefaultSchedulingContext("approved", matchingAgents); assertThat(context.findAgentsMatching(new ResourceConfigs()), is(matchingAgents)); }
public static StageConfig stageConfigWithArtifact(String stageName, String jobName, ArtifactType artifactType) { ArtifactConfigs artifactConfigsWithTests = new ArtifactConfigs(); artifactConfigsWithTests.add(createArtifactConfig(artifactType)); JobConfig job1 = new JobConfig(new CaseInsensitiveString(jobName), new ResourceConfigs("abc"), artifactConfigsWithTests); StageConfig stage = new StageConfig(new CaseInsensitiveString(stageName), new JobConfigs(job1)); return stage; }
@Test public void shouldValidateTree(){ ResourceConfig resourceConfig1 = new ResourceConfig("a#"); ResourceConfig resourceConfig2 = new ResourceConfig("b"); ResourceConfigs resourceConfigs = new ResourceConfigs(resourceConfig1, resourceConfig2); resourceConfigs.validateTree(PipelineConfigSaveValidationContext.forChain(true, "group", new PipelineConfig())); assertThat(resourceConfig1.errors().size(), is(1)); assertThat(resourceConfig1.errors().firstError(), is(String.format("Resource name 'a#' is not valid. Valid names much match '%s'", ResourceConfig.VALID_REGEX))); assertThat(resourceConfig2.errors().isEmpty(), is(true)); } }
public static StageConfig twoBuildPlansWithResourcesAndMaterials(String stageName) { JobConfig windoze = new JobConfig( new CaseInsensitiveString("WinBuild"), new ResourceConfigs(new ResourceConfig("Windows"), new ResourceConfig(".NET")), new ArtifactConfigs(Arrays.asList(new TestArtifactConfig("junit", "junit"))) ); JobConfig linux = new JobConfig( new CaseInsensitiveString("NixBuild"), new ResourceConfigs(new ResourceConfig("Linux"), new ResourceConfig("java")), new ArtifactConfigs(Arrays.asList(new TestArtifactConfig("junit", "junit"))) ); JobConfigs jobConfigs = new JobConfigs(windoze, linux); return stageConfig(stageName, jobConfigs); }
@Test public void shouldCreateJobPlan() { ResourceConfigs resourceConfigs = new ResourceConfigs(); ArtifactConfigs artifactConfigs = new ArtifactConfigs(); JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test"), resourceConfigs, artifactConfigs); JobPlan plan = instanceFactory.createJobPlan(jobConfig, new DefaultSchedulingContext()); assertThat(plan, is(new DefaultJobPlan(new Resources(resourceConfigs), ArtifactPlan.toArtifactPlans(artifactConfigs), new ArrayList<>(), -1, new JobIdentifier(), null, new EnvironmentVariables(), new EnvironmentVariables(), null))); }
@Test public void shouldAddErrorTheMessageOnTheRightFieldOfTheRightElement() throws NoSuchFieldException { ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.setName("#{not-found}"); PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("cruise", "dev", "ant"); pipelineConfig.setLabelTemplate("#a"); pipelineConfig.get(0).getJobs().addJobWithoutValidityAssertion(new JobConfig(new CaseInsensitiveString("another"), new ResourceConfigs(resourceConfig), new ArtifactConfigs())); new ParamResolver(new ParamSubstitutionHandlerFactory(params(param("foo", "pavan"), param("bar", "jj"))), fieldCache).resolve(pipelineConfig); assertThat(pipelineConfig.errors().on("labelTemplate"), is("Error when processing params for '#a' used in field 'labelTemplate', # must be followed by a parameter pattern or escaped by another #")); assertThat(resourceConfig.errors().on(JobConfig.RESOURCES), is("Parameter 'not-found' is not defined. All pipelines using this parameter directly or via a template must define it.")); }