Search in sources :

Example 1 with ElasticProfile

use of com.thoughtworks.go.config.elastic.ElasticProfile in project gocd by gocd.

the class AgentInstanceTest method shouldNotMatchJobPlanIfJobRequiresElasticAgent_MatchingIsManagedByBuildAssignmentService.

@Test
public void shouldNotMatchJobPlanIfJobRequiresElasticAgent_MatchingIsManagedByBuildAssignmentService() {
    AgentConfig agentConfig = new AgentConfig("uuid");
    agentConfig.setElasticAgentId("elastic-agent-id-1");
    String elasticPluginId = "elastic-plugin-id-1";
    agentConfig.setElasticPluginId(elasticPluginId);
    AgentInstance agentInstance = new AgentInstance(agentConfig, REMOTE, mock(SystemEnvironment.class));
    DefaultJobPlan jobPlan1 = new DefaultJobPlan();
    jobPlan1.setElasticProfile(new ElasticProfile("foo", elasticPluginId));
    List<JobPlan> jobPlans = asList(jobPlan1, new DefaultJobPlan());
    assertThat(agentInstance.firstMatching(jobPlans), is(nullValue()));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 2 with ElasticProfile

use of com.thoughtworks.go.config.elastic.ElasticProfile in project gocd by gocd.

the class AgentInstanceTest method shouldNotMatchJobPlanIfTheAgentWasLaunchedByADifferentPluginFromThatConfiguredForTheJob.

@Test
public void shouldNotMatchJobPlanIfTheAgentWasLaunchedByADifferentPluginFromThatConfiguredForTheJob() {
    AgentConfig agentConfig = new AgentConfig("uuid");
    agentConfig.setElasticAgentId("elastic-agent-id-1");
    String elasticPluginId = "elastic-plugin-id-1";
    agentConfig.setElasticPluginId(elasticPluginId);
    AgentInstance agentInstance = new AgentInstance(agentConfig, REMOTE, mock(SystemEnvironment.class));
    DefaultJobPlan jobPlan1 = new DefaultJobPlan();
    jobPlan1.setElasticProfile(new ElasticProfile("foo", "elastic-plugin-id-2"));
    List<JobPlan> jobPlans = asList(jobPlan1, new DefaultJobPlan());
    assertThat(agentInstance.firstMatching(jobPlans), is(nullValue()));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 3 with ElasticProfile

use of com.thoughtworks.go.config.elastic.ElasticProfile in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method shouldCreateProfilesFromAgentConfig_asPartOfMigration86And87.

@Test
public void shouldCreateProfilesFromAgentConfig_asPartOfMigration86And87() throws Exception {
    String configXml = "<cruise schemaVersion='85'>" + "  <server serverId='dev-id'>" + "  </server>" + "  <pipelines group='first'>" + "    <pipeline name='up42'>" + "      <materials>" + "        <hg url='../manual-testing/ant_hg/dummy' />" + "      </materials>" + "  <stage name='dist'>" + "    <jobs>" + "      <job name='test'>" + "       <agentConfig pluginId='docker'>" + "         <property>" + "           <key>instance-type</key>" + "           <value>m1.small</value>" + "         </property>" + "       </agentConfig>" + "      </job>" + "    </jobs>" + "  </stage>" + "   </pipeline>" + "  </pipelines>" + "</cruise>";
    CruiseConfig migratedConfig = migrateConfigAndLoadTheNewConfig(configXml, 85);
    PipelineConfig pipelineConfig = migratedConfig.pipelineConfigByName(new CaseInsensitiveString("up42"));
    JobConfig jobConfig = pipelineConfig.getStages().get(0).getJobs().get(0);
    assertThat(migratedConfig.schemaVersion(), greaterThan(86));
    ElasticProfiles profiles = migratedConfig.server().getElasticConfig().getProfiles();
    assertThat(profiles.size(), is(1));
    ElasticProfile expectedProfile = new ElasticProfile(jobConfig.getElasticProfileId(), "docker", new ConfigurationProperty(new ConfigurationKey("instance-type"), new ConfigurationValue("m1.small")));
    ElasticProfile elasticProfile = profiles.get(0);
    assertThat(elasticProfile, is(expectedProfile));
}
Also used : ElasticProfiles(com.thoughtworks.go.config.elastic.ElasticProfiles) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 4 with ElasticProfile

use of com.thoughtworks.go.config.elastic.ElasticProfile in project gocd by gocd.

the class ElasticAgentProfileCreateCommandTest method shouldInvokePluginValidationsBeforeSave.

@Test
public void shouldInvokePluginValidationsBeforeSave() throws Exception {
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("key", "error"));
    when(extension.validate(eq("aws"), Matchers.<Map<String, String>>any())).thenReturn(validationResult);
    ElasticProfile newProfile = new ElasticProfile("foo", "aws", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
    PluginProfileCommand command = new ElasticAgentProfileCreateCommand(mock(GoConfigService.class), newProfile, extension, null, new HttpLocalizedOperationResult());
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    thrown.expect(PluginProfileNotFoundException.class);
    thrown.expectMessage("Elastic agent profile `foo` does not exist.");
    command.isValid(cruiseConfig);
    command.update(cruiseConfig);
    assertThat(newProfile.first().errors().size(), is(1));
    assertThat(newProfile.first().errors().asString(), is("error"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 5 with ElasticProfile

use of com.thoughtworks.go.config.elastic.ElasticProfile in project gocd by gocd.

the class ElasticAgentProfileDeleteCommandTest method shouldValidateIfProfileIsNotInUseByPipeline.

@Test
public void shouldValidateIfProfileIsNotInUseByPipeline() throws Exception {
    ElasticProfile elasticProfile = new ElasticProfile("foo", "docker");
    assertThat(cruiseConfig.server().getElasticConfig().getProfiles(), is(empty()));
    ElasticAgentProfileDeleteCommand command = new ElasticAgentProfileDeleteCommand(null, elasticProfile, null, null, new HttpLocalizedOperationResult());
    assertTrue(command.isValid(cruiseConfig));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Aggregations

ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)29 Test (org.junit.Test)23 ElasticProfiles (com.thoughtworks.go.config.elastic.ElasticProfiles)9 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)6 ElasticConfig (com.thoughtworks.go.config.elastic.ElasticConfig)4 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)4 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)4 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 Gson (com.google.gson.Gson)1 Agents (com.thoughtworks.go.config.Agents)1 ArtifactPlans (com.thoughtworks.go.config.ArtifactPlans)1 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 DefaultJobPlan (com.thoughtworks.go.domain.DefaultJobPlan)1 DefaultSchedulingContext (com.thoughtworks.go.domain.DefaultSchedulingContext)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)1