Search in sources :

Example 26 with PipelineConfiguration

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

the class RunConfigurationLoaderTest method shouldLoadRunConfigurationTest.

@Test
void shouldLoadRunConfigurationTest() throws EntityNotFoundException {
    Pipeline pipeline = new Pipeline();
    pipeline.setId(1L);
    pipeline.setName(TEST_NAME);
    PipelineConfiguration pipelineConfiguration = new PipelineConfiguration();
    pipelineConfiguration.setDockerImage(TEST_PATH);
    RunConfigurationEntry entry = new RunConfigurationEntry();
    entry.setPipelineId(pipeline.getId());
    entry.setPipelineVersion(TEST_VERSION);
    entry.setName(TEST_NAME);
    entry.setConfiguration(pipelineConfiguration);
    RunConfiguration runConfiguration = new RunConfiguration();
    runConfiguration.setId(1L);
    runConfiguration.setName(TEST_NAME);
    runConfiguration.setDescription(TEST_VALUE);
    runConfiguration.setOwner(TEST_NAME);
    runConfiguration.setEntries(Collections.singletonList(entry));
    RunConfigurationDoc expectedConfiguration = RunConfigurationDoc.builder().configuration(runConfiguration).pipelines(Collections.singletonList(pipeline)).build();
    RunConfigurationLoader runConfigurationLoader = new RunConfigurationLoader(apiClient);
    when(apiClient.loadRunConfiguration(anyLong())).thenReturn(runConfiguration);
    when(apiClient.loadPipeline(anyString())).thenReturn(pipeline);
    Optional<EntityContainer<RunConfigurationDoc>> container = runConfigurationLoader.loadEntity(1L);
    EntityContainer<RunConfigurationDoc> configurationDocContainer = container.orElseThrow(AssertionError::new);
    RunConfigurationDoc actualConfiguration = configurationDocContainer.getEntity();
    assertNotNull(actualConfiguration);
    verifyConfiguration(expectedConfiguration.getConfiguration(), actualConfiguration.getConfiguration());
    verifyPipeline(expectedConfiguration.getPipelines(), actualConfiguration.getPipelines());
    verifyPipelineUser(configurationDocContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, configurationDocContainer.getPermissions());
    verifyMetadata(EXPECTED_METADATA, new ArrayList<>(configurationDocContainer.getMetadata().values()));
}
Also used : RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) RunConfigurationDoc(com.epam.pipeline.elasticsearchagent.model.RunConfigurationDoc) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) RunConfigurationEntry(com.epam.pipeline.entity.configuration.RunConfigurationEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) LoaderVerificationUtils.verifyPipeline(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyPipeline) Test(org.junit.jupiter.api.Test)

Example 27 with PipelineConfiguration

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

the class AutoscaleManager method getNewRunInstance.

private RunInstance getNewRunInstance(String runId) throws GitClientException {
    Long longRunId = Long.parseLong(runId);
    PipelineRun run = pipelineRunManager.loadPipelineRun(longRunId);
    RunInstance instance;
    if (run.getInstance() == null || run.getInstance().isEmpty()) {
        PipelineConfiguration configuration = pipelineRunManager.loadRunConfiguration(longRunId);
        instance = clusterManager.configurationToInstance(configuration);
    } else {
        instance = clusterManager.fillInstance(run.getInstance());
    }
    if (instance.getSpot() != null && instance.getSpot() && spotNodeUpAttempts.getOrDefault(longRunId, 0) >= preferenceManager.getPreference(SystemPreferences.CLUSTER_SPOT_MAX_ATTEMPTS)) {
        instance.setSpot(false);
        pipelineRunManager.updateRunInstance(longRunId, instance);
    }
    return instance;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration)

Example 28 with PipelineConfiguration

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

the class InstanceOfferManager method getInstanceEstimatedPrice.

public InstancePrice getInstanceEstimatedPrice(Long id, String version, String configName, String instanceType, int instanceDisk, Boolean spot, Long regionId) throws GitClientException {
    Boolean useSpot = spot;
    if (StringUtils.isEmpty(instanceType) || instanceDisk <= 0 || useSpot == null) {
        PipelineConfiguration pipelineConfiguration = versionManager.loadParametersFromScript(id, version, configName);
        if (StringUtils.isEmpty(instanceType)) {
            instanceType = pipelineConfiguration.getInstanceType();
        }
        if (instanceDisk <= 0) {
            instanceDisk = Integer.parseInt(pipelineConfiguration.getInstanceDisk());
        }
        if (useSpot == null) {
            useSpot = pipelineConfiguration.getIsSpot();
        }
    }
    Assert.isTrue(isInstanceAllowed(instanceType), messageHelper.getMessage(MessageConstants.ERROR_INSTANCE_TYPE_IS_NOT_ALLOWED, instanceType));
    AwsRegion region = awsRegionManager.loadRegionOrGetDefault(regionId);
    double pricePerHourForInstance = getPricePerHourForInstance(instanceType, isSpotRequest(useSpot), region.getAwsRegionName());
    double pricePerDisk = getPriceForDisk(instanceDisk, region.getAwsRegionName());
    double pricePerHour = pricePerDisk + pricePerHourForInstance;
    InstancePrice instancePrice = new InstancePrice(instanceType, instanceDisk, pricePerHour);
    List<PipelineRun> runs = pipelineRunManager.loadAllRunsByPipeline(id, version).stream().filter(run -> run.getStatus().isFinal()).collect(Collectors.toList());
    if (!runs.isEmpty()) {
        long minimumDuration = -1;
        long maximumDuration = -1;
        long totalDurations = 0;
        for (PipelineRun run : runs) {
            long duration = run.getEndDate().getTime() - run.getStartDate().getTime();
            if (minimumDuration == -1 || minimumDuration > duration) {
                minimumDuration = duration;
            }
            if (maximumDuration == -1 || maximumDuration < duration) {
                maximumDuration = duration;
            }
            totalDurations += duration;
        }
        double averageDuration = (double) totalDurations / runs.size();
        instancePrice.setAverageTimePrice(pricePerHour * averageDuration / ONE_HOUR);
        instancePrice.setMinimumTimePrice(pricePerHour * minimumDuration / ONE_HOUR);
        instancePrice.setMaximumTimePrice(pricePerHour * maximumDuration / ONE_HOUR);
    }
    return instancePrice;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Arrays(java.util.Arrays) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) URL(java.net.URL) Date(java.util.Date) BehaviorSubject(io.reactivex.subjects.BehaviorSubject) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) MessageHelper(com.epam.pipeline.common.MessageHelper) ContextualPreferenceManager(com.epam.pipeline.manager.contextual.ContextualPreferenceManager) ListUtils(org.apache.commons.collections4.ListUtils) AntPathMatcher(org.springframework.util.AntPathMatcher) AllowedInstanceAndPriceTypes(com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes) InstancePrice(com.epam.pipeline.entity.cluster.InstancePrice) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Set(java.util.Set) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Collectors(java.util.stream.Collectors) ContextualPreferenceLevel(com.epam.pipeline.entity.contextual.ContextualPreferenceLevel) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) MessageConstants(com.epam.pipeline.common.MessageConstants) GitClientException(com.epam.pipeline.exception.git.GitClientException) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) PipelineRunPrice(com.epam.pipeline.entity.cluster.PipelineRunPrice) AtomicReference(java.util.concurrent.atomic.AtomicReference) PipelineVersionManager(com.epam.pipeline.manager.pipeline.PipelineVersionManager) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) InstanceOffer(com.epam.pipeline.entity.cluster.InstanceOffer) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) Observable(io.reactivex.Observable) Subject(io.reactivex.subjects.Subject) AbstractSystemPreference(com.epam.pipeline.manager.preference.AbstractSystemPreference) InstanceOfferRequestVO(com.epam.pipeline.controller.vo.InstanceOfferRequestVO) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) InstanceOfferDao(com.epam.pipeline.dao.cluster.InstanceOfferDao) BufferedReader(java.io.BufferedReader) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) AwsRegionManager(com.epam.pipeline.manager.region.AwsRegionManager) NoArgsConstructor(lombok.NoArgsConstructor) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) InstancePrice(com.epam.pipeline.entity.cluster.InstancePrice) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration)

Example 29 with PipelineConfiguration

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

the class PipelineRunManager method runPod.

/**
 * Creates a new pod with a given run_id, doesn't create a new pipeline run
 * @param runVO
 * @return
 */
// TODO: refactoring
@ToolSecurityPolicyCheck
@Transactional(propagation = Propagation.REQUIRED)
public PipelineRun runPod(PipelineStart runVO) {
    Assert.notNull(runVO.getCmdTemplate(), messageHelper.getMessage(MessageConstants.SETTING_IS_NOT_PROVIDED, "cmd_template"));
    PipelineRun parentRun = loadPipelineRun(runVO.getUseRunId());
    Assert.state(parentRun.getStatus() == TaskStatus.RUNNING, messageHelper.getMessage(MessageConstants.ERROR_PIPELINE_RUN_NOT_RUNNING, runVO.getUseRunId()));
    PipelineConfiguration configuration = configurationManager.getPipelineConfiguration(runVO);
    Tool tool = getToolForRun(configuration);
    configuration.setSecretName(tool.getSecretName());
    List<String> endpoints = tool.getEndpoints();
    PipelineRun run = new PipelineRun();
    run.setInstance(parentRun.getInstance());
    run.setId(runVO.getUseRunId());
    run.setStartDate(DateUtils.now());
    run.setStatus(TaskStatus.RUNNING);
    run.setPipelineName(DEFAULT_PIPELINE_NAME);
    run.setPodId(getRootPodIDFromTool(tool.getImage(), run.getId()));
    run.setDockerImage(configuration.getDockerImage());
    run.setCmdTemplate(determinateCmdTemplateForRun(configuration));
    run.setTimeout(runVO.getTimeout());
    run.setCommitStatus(CommitStatus.NOT_COMMITTED);
    run.setLastChangeCommitTime(DateUtils.now());
    run.setRunSids(runVO.getRunSids());
    run.setOwner(parentRun.getOwner());
    String launchedCommand = pipelineLauncher.launch(run, configuration, endpoints, runVO.getUseRunId().toString(), false, parentRun.getPodId(), null);
    run.setActualCmd(launchedCommand);
    return run;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Tool(com.epam.pipeline.entity.pipeline.Tool) ToolSecurityPolicyCheck(com.epam.pipeline.manager.docker.scan.ToolSecurityPolicyCheck) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with PipelineConfiguration

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

the class PipelineConfigurationManager method mergeParameters.

public PipelineConfiguration mergeParameters(PipelineStart runVO, PipelineConfiguration defaultConfig) {
    Map<String, PipeConfValueVO> params = runVO.getParams() == null ? Collections.emptyMap() : runVO.getParams();
    PipelineConfiguration configuration = new PipelineConfiguration();
    configuration.setMainFile(defaultConfig.getMainFile());
    configuration.setMainClass(defaultConfig.getMainClass());
    configuration.setEnvironmentParams(defaultConfig.getEnvironmentParams());
    configuration.setPrettyUrl(runVO.getPrettyUrl());
    Map<String, PipeConfValueVO> runParameters = new LinkedHashMap<>();
    // filter and get parameters from user
    params.entrySet().stream().filter(entry -> entry.getValue().isRequired() || !StringUtils.isEmpty(entry.getValue().getValue())).forEach(entry -> runParameters.put(entry.getKey(), entry.getValue()));
    // fill in default values, only if user's value wasn't provided
    if (defaultConfig.getParameters() != null) {
        defaultConfig.getParameters().entrySet().stream().filter(entry -> entry.getValue().isRequired() || !StringUtils.isEmpty(entry.getValue().getValue())).forEach(entry -> runParameters.putIfAbsent(entry.getKey(), entry.getValue()));
    }
    // set parameters to the final configuration
    configuration.setParameters(runParameters);
    // fill instance settings
    if (runVO.getHddSize() != null) {
        configuration.setInstanceDisk(String.valueOf(runVO.getHddSize()));
    } else {
        configuration.setInstanceDisk(defaultConfig.getInstanceDisk());
    }
    if (runVO.getInstanceType() != null) {
        configuration.setInstanceType(String.valueOf(runVO.getInstanceType()));
    } else {
        configuration.setInstanceType(defaultConfig.getInstanceType());
    }
    if (runVO.getTimeout() != null) {
        configuration.setTimeout(runVO.getTimeout());
    } else {
        configuration.setTimeout(defaultConfig.getTimeout());
    }
    // client always sends actual node-count
    configuration.setNodeCount(runVO.getNodeCount());
    configuration.setCmdTemplate(runVO.getCmdTemplate() == null ? defaultConfig.getCmdTemplate() : runVO.getCmdTemplate());
    Boolean isSpot = runVO.getIsSpot() == null ? defaultConfig.getIsSpot() : runVO.getIsSpot();
    configuration.setIsSpot(isSpot);
    if (isSpot != null && !isSpot) {
        configuration.setNonPause(runVO.isNonPause());
    }
    configuration.setWorkerCmd(runVO.getWorkerCmd() == null ? defaultConfig.getWorkerCmd() : runVO.getWorkerCmd());
    configuration.setDockerImage(chooseDockerImage(runVO, defaultConfig));
    configuration.buildEnvVariables();
    return configuration;
}
Also used : PermissionsService(com.epam.pipeline.manager.security.PermissionsService) MessageConstants(com.epam.pipeline.common.MessageConstants) GitClientException(com.epam.pipeline.exception.git.GitClientException) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) PipeConfValueVO(com.epam.pipeline.entity.configuration.PipeConfValueVO) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) LinkedHashMap(java.util.LinkedHashMap) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) DataStorageApiService(com.epam.pipeline.manager.datastorage.DataStorageApiService) MessageHelper(com.epam.pipeline.common.MessageHelper) Service(org.springframework.stereotype.Service) AclPermission(com.epam.pipeline.security.acl.AclPermission) Map(java.util.Map) ConfigurationEntry(com.epam.pipeline.entity.configuration.ConfigurationEntry) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) MapUtils(org.apache.commons.collections4.MapUtils) GitManager(com.epam.pipeline.manager.git.GitManager) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Collectors(java.util.stream.Collectors) NFSDataStorage(com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage) Tool(com.epam.pipeline.entity.pipeline.Tool) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Optional(java.util.Optional) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) ToolVersionManager(com.epam.pipeline.manager.docker.ToolVersionManager) Collections(java.util.Collections) AwsRegionManager(com.epam.pipeline.manager.region.AwsRegionManager) StringUtils(org.springframework.util.StringUtils) PipeConfValueVO(com.epam.pipeline.entity.configuration.PipeConfValueVO) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) LinkedHashMap(java.util.LinkedHashMap)

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