Search in sources :

Example 66 with ClusterProfile

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

the class ClusterProfilesServiceIntegrationTest method shouldDeleteExistingClusterProfile.

@Test
public void shouldDeleteExistingClusterProfile() {
    String clusterId = "cluster1";
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ClusterProfile clusterProfile = new ClusterProfile(clusterId, "pluginid");
    clusterProfilesService.create(clusterProfile, new Username("Bob"), new HttpLocalizedOperationResult());
    assertThat(clusterProfilesService.getPluginProfiles().size(), is(1));
    assertThat(clusterProfilesService.getPluginProfiles().find(clusterId), is(clusterProfile));
    clusterProfilesService.delete(clusterProfile, new Username("Bob"), result);
    assertThat(result.isSuccessful(), is(true));
    assertThat(clusterProfilesService.getPluginProfiles().size(), is(0));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 67 with ClusterProfile

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

the class PermissionsServiceIntegrationTest method shouldShowUserSpecificClusterProfiles.

@Test
public void shouldShowUserSpecificClusterProfiles() {
    goConfigService.updateConfig(cruiseConfig -> {
        defineSecurity(cruiseConfig);
        definePolicy(cruiseConfig, "cluster_profile", "prod*", "dev*");
        ClusterProfile devCluster = new ClusterProfile("dev-cluster", "ecs");
        ClusterProfile prodCluster = new ClusterProfile("prod-cluster", "ecs");
        cruiseConfig.getElasticConfig().getClusterProfiles().addAll(Arrays.asList(devCluster, prodCluster));
        return cruiseConfig;
    });
    Map<String, Object> permissions = permissionsService.getPermissions(Arrays.asList("cluster_profile"));
    Map<String, Object> expectedClusterProfiles = new LinkedHashMap<>();
    expectedClusterProfiles.put("view", Arrays.asList("dev-cluster", "prod-cluster"));
    expectedClusterProfiles.put("administer", Arrays.asList("dev-cluster"));
    assertThat(permissions.get("cluster_profile")).isEqualTo(expectedClusterProfiles);
}
Also used : ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 68 with ClusterProfile

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

the class PermissionsServiceIntegrationTest method shouldShowUserSpecificElasticAgentProfiles.

@Test
public void shouldShowUserSpecificElasticAgentProfiles() {
    goConfigService.updateConfig(cruiseConfig -> {
        defineSecurity(cruiseConfig);
        definePolicy(cruiseConfig, "cluster_profile", "prod*", "dev*");
        ClusterProfile devCluster = new ClusterProfile("dev-cluster", "ecs");
        ClusterProfile prodCluster = new ClusterProfile("prod-cluster", "ecs");
        cruiseConfig.getElasticConfig().getClusterProfiles().addAll(Arrays.asList(devCluster, prodCluster));
        ElasticProfile buildAgent = new ElasticProfile("build-agent", "dev-cluster");
        ElasticProfile deployAgent = new ElasticProfile("deploy-agent", "prod-cluster");
        cruiseConfig.getElasticConfig().getProfiles().addAll(Arrays.asList(buildAgent, deployAgent));
        return cruiseConfig;
    });
    Map<String, Object> permissions = permissionsService.getPermissions(Arrays.asList("elastic_agent_profile"));
    Map<String, Object> expectedElasticProfiles = new LinkedHashMap<>();
    expectedElasticProfiles.put("view", Arrays.asList("build-agent", "deploy-agent"));
    expectedElasticProfiles.put("administer", Arrays.asList("build-agent"));
    assertThat(permissions.get("elastic_agent_profile")).isEqualTo(expectedElasticProfiles);
}
Also used : ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 69 with ClusterProfile

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

the class ScheduleServiceIntegrationTest method shouldSendCreateAgentRequestToPluginForTheJobRequiringElasticAgentWhichHasBeenRescheduled.

@Test
public // This test is written to verify fix for github issue https://github.com/gocd/gocd/issues/6615
void shouldSendCreateAgentRequestToPluginForTheJobRequiringElasticAgentWhichHasBeenRescheduled() {
    String pluginId = "ecs";
    ClusterProfile clusterProfile = new ClusterProfile("cluster_profile", pluginId);
    ElasticProfile elasticAgentProfile = new ElasticProfile("elastic_agent_profile", "cluster_profile");
    String ephemeralAutoRegisterKey = "auto_registry_key";
    // Mock elastic agent extension
    ElasticAgentPluginRegistry elasticAgentPluginRegistry = mock(ElasticAgentPluginRegistry.class);
    when(elasticAgentPluginRegistry.shouldAssignWork(any(), any(), any(), any(), any(), any())).thenReturn(true);
    when(elasticAgentPluginRegistry.has(any())).thenReturn(true);
    when(ephemeralAutoRegisterKeyService.autoRegisterKey()).thenReturn(ephemeralAutoRegisterKey);
    elasticAgentPluginService.setElasticAgentPluginRegistry(elasticAgentPluginRegistry);
    elasticAgentPluginService.setEphemeralAutoRegisterKeyService(ephemeralAutoRegisterKeyService);
    // Mock CreateAgentQueueHandler to verify create agent call was sent to the plugin
    CreateAgentQueueHandler createAgentQueueHandler = mock(CreateAgentQueueHandler.class);
    elasticAgentPluginService.setCreateAgentQueue(createAgentQueueHandler);
    // add a cluster profile and elastic agent profile to the config.
    GoConfigDao goConfigDao = configHelper.getGoConfigDao();
    goConfigDao.loadForEditing().getElasticConfig().getClusterProfiles().add(clusterProfile);
    goConfigDao.loadForEditing().getElasticConfig().getProfiles().add(elasticAgentProfile);
    // create 2 elastic agents for ecs plugin
    Agent agent = AgentMother.elasticAgent();
    agent.setElasticAgentId("elastic-agent-id-1");
    agent.setElasticPluginId(pluginId);
    Agent agentConfig2 = AgentMother.elasticAgent();
    agentConfig2.setElasticAgentId("elastic-agent-id-2");
    agentConfig2.setElasticPluginId(pluginId);
    dbHelper.addAgent(agent);
    dbHelper.addAgent(agentConfig2);
    // define a job in the config requiring elastic agent
    PipelineConfig pipelineToBeAdded = PipelineConfigMother.createPipelineConfigWithStages(UUID.randomUUID().toString(), "s1");
    pipelineToBeAdded.first().getJobs().first().setElasticProfileId("elastic_agent_profile");
    PipelineConfig pipelineConfig = configHelper.addPipeline(pipelineToBeAdded);
    // trigger the pipeline
    Pipeline pipeline = dbHelper.schedulePipeline(pipelineConfig, forceBuild(pipelineConfig), "Bob", new TimeProvider(), Collections.singletonMap("elastic_agent_profile", elasticAgentProfile), Collections.singletonMap("cluster_profile", clusterProfile));
    buildAssignmentService.onTimer();
    // verify no agents are building
    AgentInstance agent1 = agentService.findAgent(agent.getUuid());
    assertFalse(agent1.isBuilding());
    AgentInstance agent2 = agentService.findAgent(agentConfig2.getUuid());
    assertFalse(agent2.isBuilding());
    // assign the current job to elastic agent 1
    Work work = buildAssignmentService.assignWorkToAgent(agent(agent));
    assertThat(work, instanceOf(BuildWork.class));
    assertTrue(agent1.isBuilding());
    // reschedule the job
    scheduleService.rescheduleJob(pipeline.getFirstStage().getFirstJob());
    // when the job is rescheduled, the current job instance is marked as rescheduled and a job with new build id is created for it.
    long existingRescheduledBuildId = pipeline.getFirstStage().getFirstJob().getId();
    // newly scheduled build will have the next counter.
    long newlyScheduledBuildId = pipeline.getFirstStage().getFirstJob().getId() + 1;
    // existing job instance, which is rescheduled
    JobInstance existingRescheduledInstance = jobInstanceService.buildById(existingRescheduledBuildId);
    // newly created job instance
    JobInstance newlyScheduledInstance = jobInstanceService.buildById(newlyScheduledBuildId);
    assertThat(existingRescheduledInstance.getState(), is(JobState.Rescheduled));
    assertThat(newlyScheduledInstance.getState(), is(JobState.Scheduled));
    // verify the newly created instance's job plan include elastic profile and cluster profile
    assertThat(jobInstanceDao.loadPlan(newlyScheduledBuildId).getClusterProfile(), is(clusterProfile));
    assertThat(jobInstanceDao.loadPlan(newlyScheduledBuildId).getElasticProfile(), is(elasticAgentProfile));
    JobPlan jobPlanOfRescheduledInstance = jobInstanceDao.loadPlan(existingRescheduledBuildId);
    // invoke jobStatusListener to simulate first agent reporting job completed scenario
    jobStatusListener.onMessage(new JobStatusMessage(jobPlanOfRescheduledInstance.getIdentifier(), JobState.Completed, jobPlanOfRescheduledInstance.getAgentUuid()));
    // verify the newly created instance's job plan include elastic profile and cluster profile even after the first agent reports job completion
    assertThat(jobInstanceDao.loadPlan(newlyScheduledBuildId).getClusterProfile(), is(clusterProfile));
    assertThat(jobInstanceDao.loadPlan(newlyScheduledBuildId).getElasticProfile(), is(elasticAgentProfile));
    elasticAgentPluginService.createAgentsFor(Collections.emptyList(), Collections.singletonList(jobInstanceDao.loadPlan(newlyScheduledBuildId)));
    // verify create agent request was sent to the plugin
    CreateAgentMessage message = new CreateAgentMessage(ephemeralAutoRegisterKey, null, elasticAgentProfile, clusterProfile, jobPlanOfRescheduledInstance.getIdentifier());
    verify(createAgentQueueHandler, times(1)).post(message, 110000L);
}
Also used : CreateAgentMessage(com.thoughtworks.go.server.messaging.elasticagents.CreateAgentMessage) TimeProvider(com.thoughtworks.go.util.TimeProvider) BuildWork(com.thoughtworks.go.remote.work.BuildWork) JobStatusMessage(com.thoughtworks.go.server.messaging.JobStatusMessage) ElasticAgentPluginRegistry(com.thoughtworks.go.plugin.access.elastic.ElasticAgentPluginRegistry) BuildWork(com.thoughtworks.go.remote.work.BuildWork) Work(com.thoughtworks.go.remote.work.Work) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) CreateAgentQueueHandler(com.thoughtworks.go.server.messaging.elasticagents.CreateAgentQueueHandler) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)69 Test (org.junit.jupiter.api.Test)39 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)32 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)14 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)12 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)10 ClusterProfiles (com.thoughtworks.go.config.elastic.ClusterProfiles)8 Username (com.thoughtworks.go.server.domain.Username)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ElasticConfig (com.thoughtworks.go.config.elastic.ElasticConfig)6 Capabilities (com.thoughtworks.go.plugin.domain.elastic.Capabilities)6 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)5 JobAgentMetadata (com.thoughtworks.go.domain.JobAgentMetadata)4 ElasticAgentInformation (com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)4 GoCipher (com.thoughtworks.go.security.GoCipher)4