Search in sources :

Example 11 with PipelineConfiguration

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

the class ToolVersionDaoTest method shouldCRUDWithSettings.

@Test
public void shouldCRUDWithSettings() {
    Long toolId = tool.getId();
    PipelineConfiguration pipelineConfiguration = new PipelineConfiguration();
    pipelineConfiguration.setCmdTemplate(TEST_CMD_TEMPLATE_1);
    pipelineConfiguration.setNodeCount(TEST_NODE_COUNT);
    pipelineConfiguration.setParameters(Collections.singletonMap(TEST_PARAMETER_NAME, new PipeConfValueVO(TEST_PARAMETER_VALUE)));
    ConfigurationEntry configurationEntry = new ConfigurationEntry(pipelineConfiguration);
    List<ConfigurationEntry> settings = Collections.singletonList(configurationEntry);
    toolVersion1.setSettings(settings);
    toolVersionDao.createToolVersionWithSettings(toolVersion1);
    ToolVersion actual = toolVersionDao.loadToolVersionWithSettings(toolId, TEST_VERSION).orElse(null);
    validateToolVersionSettings(actual, configurationEntry, TEST_VERSION, toolId, TEST_PARAMETER_NAME);
    pipelineConfiguration.setCmdTemplate(TEST_CMD_TEMPLATE_2);
    configurationEntry.setConfiguration(pipelineConfiguration);
    settings = Collections.singletonList(configurationEntry);
    toolVersion1.setSettings(settings);
    toolVersionDao.updateToolVersionWithSettings(toolVersion1);
    actual = toolVersionDao.loadToolVersionWithSettings(toolId, TEST_VERSION).orElse(null);
    validateToolVersionSettings(actual, configurationEntry, TEST_VERSION, toolId, TEST_PARAMETER_NAME);
    toolVersionDao.deleteToolVersions(toolId);
    actual = toolVersionDao.loadToolVersion(toolId, TEST_VERSION).orElse(null);
    assertThat(actual).isNull();
}
Also used : PipeConfValueVO(com.epam.pipeline.entity.configuration.PipeConfValueVO) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) ConfigurationEntry(com.epam.pipeline.entity.configuration.ConfigurationEntry) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 12 with PipelineConfiguration

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

the class ClusterManagerImpl method configurationToInstance.

@Override
public RunInstance configurationToInstance(PipelineConfiguration configuration) {
    RunInstance instance = new RunInstance();
    if (configuration.getInstanceType() == null) {
        instance.setNodeType(preferenceManager.getPreference(SystemPreferences.CLUSTER_INSTANCE_TYPE));
    } else {
        instance.setNodeType(configuration.getInstanceType());
    }
    if (configuration.getInstanceDisk() == null) {
        instance.setNodeDisk(preferenceManager.getPreference(SystemPreferences.CLUSTER_INSTANCE_HDD));
    } else {
        instance.setNodeDisk(Integer.parseInt(configuration.getInstanceDisk()));
    }
    instance.setEffectiveNodeDisk(instance.getNodeDisk());
    if (configuration.getInstanceImage() == null) {
        instance.setNodeImage(preferenceManager.getPreference(SystemPreferences.CLUSTER_INSTANCE_IMAGE));
    } else {
        instance.setNodeImage(configuration.getInstanceImage());
    }
    instance.setAwsRegionId(Optional.ofNullable(configuration.getAwsRegionId()).map(regionId -> awsRegionManager.load(regionId)).orElse(awsRegionManager.loadDefaultRegion()).getAwsRegionName());
    return instance;
}
Also used : PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) UserContext(com.epam.pipeline.security.UserContext) Service(org.springframework.stereotype.Service) Duration(java.time.Duration) Map(java.util.Map) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Collectors(java.util.stream.Collectors) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) CmdExecutionException(com.epam.pipeline.exception.CmdExecutionException) UserManager(com.epam.pipeline.manager.user.UserManager) Environment(org.springframework.core.env.Environment) DateTimeFormatter(java.time.format.DateTimeFormatter) PostConstruct(javax.annotation.PostConstruct) CmdExecutor(com.epam.pipeline.manager.CmdExecutor) Clock(java.time.Clock) Optional(java.util.Optional) AuthManager(com.epam.pipeline.manager.security.AuthManager) AwsRegionManager(com.epam.pipeline.manager.region.AwsRegionManager) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance)

Example 13 with PipelineConfiguration

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

the class ToolSecurityPolicyAspect method checkToolBySecurityPolicy.

@Before("@annotation(com.epam.pipeline.manager.docker.scan.ToolSecurityPolicyCheck) && args(runVO,..)")
public void checkToolBySecurityPolicy(JoinPoint joinPoint, PipelineStart runVO) {
    if (runVO.isForce()) {
        PipelineUser user = authManager.getCurrentUser();
        if (user != null && user.isAdmin()) {
            return;
        }
    }
    PipelineConfiguration configuration = configurationManager.getPipelineConfiguration(runVO);
    String tag = toolManager.getTagFromImageName(configuration.getDockerImage());
    Tool tool = toolManager.loadByNameOrId(configuration.getDockerImage());
    if (!clairToolScanManager.checkTool(tool, tag)) {
        throw new ToolExecutionDeniedException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_SECURITY_POLICY_VIOLATION));
    }
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) ToolExecutionDeniedException(com.epam.pipeline.exception.ToolExecutionDeniedException) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Tool(com.epam.pipeline.entity.pipeline.Tool) Before(org.aspectj.lang.annotation.Before)

Example 14 with PipelineConfiguration

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

the class EnvVarsBuilder method buildEnvVars.

public static List<EnvVar> buildEnvVars(PipelineRun run, PipelineConfiguration configuration, Map<SystemParams, String> sysParams, Map<String, String> externalProperties) {
    List<EnvVar> fullEnvVars = new ArrayList<>();
    Map<String, String> envVarsMap = new HashMap<>();
    sysParams.entrySet().stream().map(sysParam -> {
        String name = sysParam.getKey().getEnvName();
        String value = sysParam.getValue();
        if (!sysParam.getKey().isSecure()) {
            envVarsMap.put(name, value);
        }
        return new EnvVar(name, value, null);
    }).forEach(fullEnvVars::add);
    configuration.getParameters().entrySet().stream().map(parameter -> {
        String name = parameter.getKey();
        String value = parameter.getValue().getValue();
        String type = parameter.getValue().getType();
        return matchParameterToEnvVars(name, value, type, envVarsMap);
    }).flatMap(Arrays::stream).forEach(fullEnvVars::add);
    configuration.getEnvironmentParams().entrySet().stream().map(parameter -> {
        String name = parameter.getKey();
        String value = parameter.getValue();
        envVarsMap.put(name, value);
        return new EnvVar(name, value, null);
    }).forEach(fullEnvVars::add);
    if (!MapUtils.isEmpty(externalProperties)) {
        externalProperties.entrySet().stream().map(property -> {
            String name = getBashName(property.getKey());
            envVarsMap.put(name, property.getValue());
            return new EnvVar(name, property.getValue(), null);
        }).forEach(fullEnvVars::add);
    }
    run.setEnvVars(envVarsMap);
    return fullEnvVars;
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Arrays(java.util.Arrays) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 15 with PipelineConfiguration

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

the class PipelineConfigurationForRunnerTest method shouldGetSpecifiedConfigurationForToolVersionRun.

@Test
public void shouldGetSpecifiedConfigurationForToolVersionRun() {
    Tool tool = new Tool();
    tool.setImage(TEST_IMAGE);
    tool.setRam(TEST_RAM);
    tool.setCpu(TEST_CPU);
    ConfigurationEntry otherConfigurationEntry = new ConfigurationEntry();
    otherConfigurationEntry.setName(TEST_CONFIGURATION_NAME);
    PipelineConfiguration pipelineConfiguration = new PipelineConfiguration();
    pipelineConfiguration.setInstanceDisk(TEST_HDD_SIZE);
    otherConfigurationEntry.setConfiguration(pipelineConfiguration);
    when(toolVersionManagerMock.loadToolVersionSettings(anyLong(), anyString())).thenReturn(Collections.singletonList(ToolVersion.builder().settings(Arrays.asList(configurationEntry, otherConfigurationEntry)).build()));
    PipelineStart vo = getPipelineStartVO();
    vo.setHddSize(null);
    vo.setConfigurationName(TEST_CONFIGURATION_NAME);
    PipelineConfiguration config = pipelineConfigurationManager.getPipelineConfiguration(vo, tool);
    commonPipelineConfigurationAssertions(config);
    assertThat(config).hasFieldOrPropertyWithValue(INSTANCE_DISK_FIELD, // from configuration
    TEST_HDD_SIZE);
    assertThat(config.getParameters()).isNotEmpty().hasSize(1).containsKeys(TEST_PARAM_1);
}
Also used : PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) ConfigurationEntry(com.epam.pipeline.entity.configuration.ConfigurationEntry) 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)

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