Search in sources :

Example 16 with PipelineConfiguration

use of com.epam.pipeline.entity.configuration.PipelineConfiguration in project cloud-pipeline by epam.

the class PipelineConfigurationForRunnerTest method shouldGetDefaultConfigurationForToolVersionRun.

@Test
public void shouldGetDefaultConfigurationForToolVersionRun() {
    Tool tool = new Tool();
    tool.setImage(TEST_IMAGE);
    tool.setRam(TEST_RAM);
    tool.setCpu(TEST_CPU);
    tool.setDisk(Integer.parseInt(TEST_HDD_SIZE));
    PipelineStart vo = getPipelineStartVO();
    vo.setHddSize(null);
    PipelineConfiguration config = pipelineConfigurationManager.getPipelineConfiguration(vo, tool);
    commonPipelineConfigurationAssertions(config);
    assertThat(config).hasFieldOrPropertyWithValue(INSTANCE_DISK_FIELD, // from tool
    TEST_HDD_SIZE);
    assertThat(config.getParameters()).isNotEmpty().hasSize(2).containsKeys(TEST_PARAM_1, // from default configuration
    TEST_PARAM_2);
}
Also used : PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Tool(com.epam.pipeline.entity.pipeline.Tool) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) Test(org.junit.Test) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest)

Example 17 with PipelineConfiguration

use of com.epam.pipeline.entity.configuration.PipelineConfiguration in project cloud-pipeline by epam.

the class PipelineConfigurationForRunnerTest method shouldGetConfigurationForPodRun.

@Test
public void shouldGetConfigurationForPodRun() {
    PipelineStart vo = getPipelineStartVO();
    PipelineConfiguration config = pipelineConfigurationManager.getPipelineConfiguration(vo);
    commonPipelineConfigurationAssertions(config);
    assertThat(config).hasFieldOrPropertyWithValue(INSTANCE_DISK_FIELD, TEST_HDD_SIZE);
    assertThat(config.getParameters()).isNotEmpty().hasSize(1).containsKeys(TEST_PARAM_1);
}
Also used : PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) Test(org.junit.Test) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest)

Example 18 with PipelineConfiguration

use of com.epam.pipeline.entity.configuration.PipelineConfiguration in project cloud-pipeline by epam.

the class PipelineConfigurationForRunnerTest method setUp.

@Before
public void setUp() throws GitClientException {
    MockitoAnnotations.initMocks(this);
    PipelineConfiguration pipelineConfiguration = new PipelineConfiguration();
    pipelineConfiguration.setWorkerCmd(TEST_WORKED_CMD);
    pipelineConfiguration.setParameters(Collections.singletonMap(TEST_PARAM_2, TEST_PARAM_VALUE));
    configurationEntry = new ConfigurationEntry();
    configurationEntry.setConfiguration(pipelineConfiguration);
    configurationEntry.setDefaultConfiguration(true);
    when(toolManagerMock.getTagFromImageName(anyString())).thenReturn("latest");
    when(gitManagerMock.getGitCredentials(anyLong())).thenReturn(null);
    when(pipelineVersionManagerMock.loadConfigurationEntry(anyLong(), anyString(), anyString())).thenReturn(configurationEntry);
    when(pipelineVersionManagerMock.getValidDockerImage(anyString())).thenReturn(TEST_IMAGE);
    when(dataStorageApiServiceMock.getWritableStorages()).thenReturn(Collections.emptyList());
    when(permissionsServiceMock.isMaskBitSet(anyInt(), anyInt())).thenReturn(true);
    when(toolVersionManagerMock.loadToolVersionSettings(anyLong(), anyString())).thenReturn(Collections.singletonList(ToolVersion.builder().settings(Collections.singletonList(configurationEntry)).build()));
}
Also used : PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) ConfigurationEntry(com.epam.pipeline.entity.configuration.ConfigurationEntry) Before(org.junit.Before)

Example 19 with PipelineConfiguration

use of com.epam.pipeline.entity.configuration.PipelineConfiguration in project cloud-pipeline by epam.

the class PipelineRunManagerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    notScannedTool = new Tool();
    notScannedTool.setId(1L);
    notScannedTool.setImage(TEST_IMAGE);
    notScannedTool.setDefaultCommand("sleep");
    configuration = new PipelineConfiguration();
    configuration.setDockerImage(TEST_IMAGE);
    configuration.setInstanceDisk("1");
    configuration.setIsSpot(true);
    price = new InstancePrice(configuration.getInstanceType(), Integer.valueOf(configuration.getInstanceDisk()), PRICE_PER_HOUR);
    when(toolManager.loadByNameOrId(TEST_IMAGE)).thenReturn(notScannedTool);
    when(instanceOfferManager.isInstanceAllowed(anyString())).thenReturn(true);
    when(instanceOfferManager.isToolInstanceAllowed(anyString(), any())).thenReturn(true);
    when(instanceOfferManager.isPriceTypeAllowed(anyString(), any())).thenReturn(true);
    when(instanceOfferManager.getAllInstanceTypesObservable()).thenReturn(BehaviorSubject.create());
    when(instanceOfferManager.getInstanceEstimatedPrice(anyString(), anyInt(), anyBoolean(), anyString())).thenReturn(price);
    when(pipelineLauncher.launch(any(PipelineRun.class), any(), any(), anyString(), anyString())).thenReturn("sleep");
    when(toolManager.loadToolVersionScan(notScannedTool.getId(), null)).thenReturn(Optional.empty());
    when(toolVersionManager.loadToolVersion(anyLong(), anyString())).thenReturn(ToolVersion.builder().size(1L).build());
    doReturn(configuration).when(pipelineConfigurationManager).getPipelineConfiguration(any());
    doReturn(configuration).when(pipelineConfigurationManager).getPipelineConfiguration(any(), any());
    AwsRegion region = new AwsRegion();
    region.setAwsRegionName("us-east-1");
    doReturn(region).when(awsRegionManager).loadDefaultRegion();
    doNothing().when(entityManager).setManagers(any());
    doNothing().when(resourceMonitoringManager).monitorResourceUsage();
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) InstancePrice(com.epam.pipeline.entity.cluster.InstancePrice) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Tool(com.epam.pipeline.entity.pipeline.Tool) Before(org.junit.Before)

Example 20 with PipelineConfiguration

use of com.epam.pipeline.entity.configuration.PipelineConfiguration in project cloud-pipeline by epam.

the class PipelineConfigurationManagerTest method testGetUnregisteredPipelineConfiguration.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
@WithMockUser(username = TEST_OWNER1)
public void testGetUnregisteredPipelineConfiguration() {
    PipelineStart vo = getPipelineStartVO();
    PipelineConfiguration config = pipelineConfigurationManager.getPipelineConfiguration(vo);
    Assert.assertFalse(config.getBuckets().isEmpty());
    Assert.assertFalse(config.getNfsMountOptions().isEmpty());
    String[] buckets = config.getBuckets().split(";");
    Assert.assertEquals(2, buckets.length);
    for (String bucket : buckets) {
        Assert.assertTrue(dataStorages.stream().anyMatch(ds -> bucket.equals(ds.getPathMask())));
    }
    String[] nfsOptions = config.getNfsMountOptions().split(";");
    Assert.assertEquals(1, nfsOptions.length);
    for (String option : nfsOptions) {
        if (StringUtils.isNotBlank(option)) {
            Assert.assertTrue(dataStorages.stream().filter(ds -> ds instanceof NFSDataStorage).anyMatch(ds -> {
                NFSDataStorage nfsDs = (NFSDataStorage) ds;
                return nfsDs.getMountOptions().equals(option) || option.equals(nfsDs.getMountOptions() + ",ro");
            }));
        }
    }
    String[] mountPoints = config.getMountPoints().split(";");
    for (String mountPoint : mountPoints) {
        if (StringUtils.isNotBlank(mountPoint)) {
            Assert.assertTrue(dataStorages.stream().anyMatch(ds -> mountPoint.equals(ds.getMountPoint())));
        }
    }
// Assert.assertTrue(Arrays.stream(nfsOptions).anyMatch(o -> o.endsWith(",ro")));
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) TestApplicationWithAclSecurity(com.epam.pipeline.app.TestApplicationWithAclSecurity) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) DataStorageDao(com.epam.pipeline.dao.datastorage.DataStorageDao) AclTestDao(com.epam.pipeline.dao.util.AclTestDao) Autowired(org.springframework.beans.factory.annotation.Autowired) PipeConfValueVO(com.epam.pipeline.entity.configuration.PipeConfValueVO) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Propagation(org.springframework.transaction.annotation.Propagation) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) AclPermission(com.epam.pipeline.security.acl.AclPermission) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Before(org.junit.Before) ToolDao(com.epam.pipeline.dao.tool.ToolDao) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Test(org.junit.Test) DockerRegistryDao(com.epam.pipeline.dao.docker.DockerRegistryDao) NFSDataStorage(com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Tool(com.epam.pipeline.entity.pipeline.Tool) List(java.util.List) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ContextConfiguration(org.springframework.test.context.ContextConfiguration) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) Assert(org.junit.Assert) ToolGroupDao(com.epam.pipeline.dao.tool.ToolGroupDao) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) NFSDataStorage(com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)43 Test (org.junit.Test)16 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)12 Tool (com.epam.pipeline.entity.pipeline.Tool)12 RunConfigurationEntry (com.epam.pipeline.entity.configuration.RunConfigurationEntry)10 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)9 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)9 PipelineStart (com.epam.pipeline.entity.pipeline.run.PipelineStart)8 List (java.util.List)7 ConfigurationEntry (com.epam.pipeline.entity.configuration.ConfigurationEntry)6 Before (org.junit.Before)6 PipeConfValueVO (com.epam.pipeline.entity.configuration.PipeConfValueVO)5 HashMap (java.util.HashMap)5 Collectors (java.util.stream.Collectors)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Transactional (org.springframework.transaction.annotation.Transactional)5 RunConfiguration (com.epam.pipeline.entity.configuration.RunConfiguration)4 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)4 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)4 ArrayList (java.util.ArrayList)4