Search in sources :

Example 1 with PipelineRunParameter

use of com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter in project cloud-pipeline by epam.

the class AutoscaleManager method getOrderedPipelines.

private List<Pod> getOrderedPipelines(List<Pod> items, KubernetesClient client) {
    Map<Pod, Long> parentIds = new HashMap<>();
    Map<Pod, Long> priorityScore = new HashMap<>();
    List<Pod> checkedPods = new ArrayList<>();
    for (Pod pod : items) {
        Long runId = Long.parseLong(pod.getMetadata().getLabels().get(KubernetesConstants.RUN_ID_LABEL));
        try {
            PipelineRun run = pipelineRunManager.loadPipelineRun(runId);
            if (run.getStatus().isFinal()) {
                LOGGER.debug("Pipeline run {} is already in final status", runId);
                continue;
            }
            if (run.getStatus() == TaskStatus.PAUSED) {
                LOGGER.debug("Pipeline run {} is paused", runId);
                continue;
            }
            List<PipelineRunParameter> runParameters = run.getPipelineRunParameters();
            if (!preferenceManager.getPreference(SystemPreferences.CLUSTER_RANDOM_SCHEDULING)) {
                getParentId(parentIds, pod, runParameters);
            }
            checkedPods.add(pod);
            priorityScore.put(pod, getParameterValue(runParameters, "priority-score", 0L));
        } catch (IllegalArgumentException e) {
            LOGGER.error("Failed to load pipeline run {}.", runId);
            LOGGER.error(e.getMessage(), e);
            // If we failed to load a matching pipeline run for a pod, we delete it here, since
            // PodMonitor wont't process it either
            deletePod(pod, client);
            removeNodeUpTask(runId);
        }
    }
    if (!CollectionUtils.isEmpty(checkedPods)) {
        checkedPods.sort((p1, p2) -> {
            if (!preferenceManager.getPreference(SystemPreferences.CLUSTER_RANDOM_SCHEDULING)) {
                Long parentId1 = parentIds.get(p1);
                Long parentId2 = parentIds.get(p2);
                if (!parentId1.equals(parentId2)) {
                    return Long.compare(parentId1, parentId2);
                }
            }
            return Long.compare(priorityScore.get(p2), priorityScore.get(p1));
        });
        return checkedPods;
    } else {
        return Collections.emptyList();
    }
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Pod(io.fabric8.kubernetes.api.model.Pod) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter)

Example 2 with PipelineRunParameter

use of com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter in project cloud-pipeline by epam.

the class PipelineRun method parseParameters.

public void parseParameters() {
    pipelineRunParameters = new ArrayList<>();
    if (StringUtils.hasText(params)) {
        String[] parts = params.split("\\|");
        pipelineRunParameters = Arrays.stream(parts).map(part -> {
            String[] chunks = part.split(KEY_VALUE_DELIMITER);
            if (chunks.length == 2) {
                return new PipelineRunParameter(chunks[0], chunks[1]);
            } else if (chunks.length == 3) {
                return new PipelineRunParameter(chunks[0], chunks[1], chunks[2]);
            }
            return new PipelineRunParameter(part);
        }).collect(Collectors.toList());
    }
    if (parentRunId != null && pipelineRunParameters.stream().noneMatch(p -> p.getName().equals(PARENT_ID_PARAM))) {
        pipelineRunParameters.add(new PipelineRunParameter(PARENT_ID_PARAM, parentRunId.toString()));
    }
}
Also used : ExecutionPreferences(com.epam.pipeline.entity.pipeline.run.ExecutionPreferences) Setter(lombok.Setter) Arrays(java.util.Arrays) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Getter(lombok.Getter) PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter) RunSid(com.epam.pipeline.entity.pipeline.run.parameter.RunSid) Date(java.util.Date) LocalDateTime(java.time.LocalDateTime) PipeConfValueVO(com.epam.pipeline.entity.configuration.PipeConfValueVO) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) List(java.util.List) RunStatus(com.epam.pipeline.entity.pipeline.run.RunStatus) ListUtils(org.apache.commons.collections4.ListUtils) Map(java.util.Map) RestartRun(com.epam.pipeline.entity.pipeline.run.RestartRun) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) AclClass(com.epam.pipeline.entity.security.acl.AclClass) Pattern(java.util.regex.Pattern) AllArgsConstructor(lombok.AllArgsConstructor) StringUtils(org.springframework.util.StringUtils) PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter)

Example 3 with PipelineRunParameter

use of com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter in project cloud-pipeline by epam.

the class PipelineRunLoaderTest method shouldLoadPipelineRunTest.

@Test
void shouldLoadPipelineRunTest() throws EntityNotFoundException {
    RunInstance instance = new RunInstance();
    instance.setNodeType("type");
    instance.setAwsRegionId(TEST_REGION);
    instance.setSpot(true);
    instance.setNodeDisk(NODE_DISK);
    instance.setNodeId("id");
    instance.setNodeImage(TEST_PATH);
    instance.setNodeName(TEST_NAME);
    RunStatus runStatus = new RunStatus();
    runStatus.setRunId(1L);
    runStatus.setStatus(TaskStatus.SUCCESS);
    PipelineRunParameter parameter = new PipelineRunParameter();
    parameter.setName(TEST_NAME);
    parameter.setValue(TEST_VALUE);
    PipelineRun expectedPipelineRun = new PipelineRun();
    expectedPipelineRun.setId(1L);
    expectedPipelineRun.setName(TEST_NAME);
    expectedPipelineRun.setPipelineName(TEST_NAME);
    expectedPipelineRun.setPipelineId(1L);
    expectedPipelineRun.setInstance(instance);
    expectedPipelineRun.setStatus(TaskStatus.SUCCESS);
    expectedPipelineRun.setVersion(TEST_VERSION);
    expectedPipelineRun.setRunStatuses(Collections.singletonList(runStatus));
    expectedPipelineRun.setPricePerHour(PRICE);
    expectedPipelineRun.setOwner(TEST_NAME);
    expectedPipelineRun.setPipelineRunParameters(Collections.singletonList(parameter));
    RunLog runLog = new RunLog();
    runLog.setLogText(TEST_DESCRIPTION);
    runLog.setStatus(TaskStatus.SUCCESS);
    runLog.setTask(new PipelineTask(TEST_NAME));
    List<RunLog> runLogs = Collections.singletonList(runLog);
    PipelineRunWithLog expectedPipelineRunWithLog = new PipelineRunWithLog();
    expectedPipelineRunWithLog.setPipelineRun(expectedPipelineRun);
    expectedPipelineRunWithLog.setRunOwner(USER);
    expectedPipelineRunWithLog.setRunLogs(runLogs);
    PipelineRunLoader pipelineRunLoader = new PipelineRunLoader(apiClient);
    when(apiClient.loadPipelineRunWithLogs(anyLong())).thenReturn(expectedPipelineRunWithLog);
    when(apiClient.loadPipelineRun(anyLong())).thenReturn(expectedPipelineRun);
    Optional<EntityContainer<PipelineRunWithLog>> container = pipelineRunLoader.loadEntity(1L);
    EntityContainer<PipelineRunWithLog> pipelineRunEntityContainer = container.orElseThrow(AssertionError::new);
    PipelineRunWithLog actualPipelineRunWithLog = pipelineRunEntityContainer.getEntity();
    assertNotNull(actualPipelineRunWithLog);
    PipelineRun actualPipelineRun = actualPipelineRunWithLog.getPipelineRun();
    assertNotNull(actualPipelineRun);
    List<RunLog> actualRunLogs = actualPipelineRunWithLog.getRunLogs();
    assertNotNull(actualRunLogs);
    verifyPipelineRun(expectedPipelineRun, actualPipelineRun);
    verifyRunInstance(expectedPipelineRun.getInstance(), actualPipelineRun.getInstance());
    verifyRunStatuses(expectedPipelineRun.getRunStatuses(), actualPipelineRun.getRunStatuses());
    verifyRunParameters(expectedPipelineRun.getPipelineRunParameters(), actualPipelineRun.getPipelineRunParameters());
    verifyRunLogs(runLogs, actualRunLogs);
    verifyPipelineUser(pipelineRunEntityContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, pipelineRunEntityContainer.getPermissions());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) LoaderVerificationUtils.verifyPipelineRun(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyPipelineRun) RunStatus(com.epam.pipeline.entity.pipeline.run.RunStatus) RunLog(com.epam.pipeline.entity.pipeline.RunLog) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) LoaderVerificationUtils.verifyRunInstance(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyRunInstance) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask) PipelineRunWithLog(com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog) PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter) Test(org.junit.jupiter.api.Test)

Example 4 with PipelineRunParameter

use of com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter in project cloud-pipeline by epam.

the class PipelineRunManagerTest method testEnvVarsReplacement.

@Test
public void testEnvVarsReplacement() {
    List<PipelineRunParameter> parameters = new ArrayList<>();
    Map<String, String> envVars = new HashMap<>();
    // case: empty collections
    List<PipelineRunParameter> actualParameters = pipelineRunManager.replaceParametersWithEnvVars(parameters, envVars);
    Assert.assertTrue(CollectionUtils.isEmpty(actualParameters));
    // case: empty env_vars
    String paramValue = "simple";
    parameters.add(new PipelineRunParameter(PARAM_NAME_1, paramValue));
    actualParameters = pipelineRunManager.replaceParametersWithEnvVars(parameters, envVars);
    Assert.assertEquals(parameters, actualParameters);
    // case: empty params
    envVars.put(ENV_VAR_NAME, ENV_VAR_VALUE);
    actualParameters = pipelineRunManager.replaceParametersWithEnvVars(new ArrayList<>(), envVars);
    Assert.assertTrue(CollectionUtils.isEmpty(actualParameters));
    // case: replacement no needed
    actualParameters = pipelineRunManager.replaceParametersWithEnvVars(parameters, envVars);
    Assert.assertEquals(paramValue, actualParameters.get(0).getValue());
    // case: ${TEST_ENV}
    paramValue = String.format("test/${%s}", ENV_VAR_NAME);
    String expectedValue = String.format("test/%s", ENV_VAR_VALUE);
    actualParameters = pipelineRunManager.replaceParametersWithEnvVars(Collections.singletonList(new PipelineRunParameter(PARAM_NAME_1, paramValue)), envVars);
    checkResolvedValue(actualParameters, paramValue, expectedValue);
    // case: $TEST_ENV at the end of the line
    paramValue = String.format("test/$%s", ENV_VAR_NAME);
    expectedValue = String.format("test/%s", ENV_VAR_VALUE);
    actualParameters = pipelineRunManager.replaceParametersWithEnvVars(Collections.singletonList(new PipelineRunParameter(PARAM_NAME_1, paramValue)), envVars);
    checkResolvedValue(actualParameters, paramValue, expectedValue);
    // case: $TEST_ENV at the middle of the line
    paramValue = String.format("test/$%s/", ENV_VAR_NAME);
    expectedValue = String.format("test/%s/", ENV_VAR_VALUE);
    actualParameters = pipelineRunManager.replaceParametersWithEnvVars(Collections.singletonList(new PipelineRunParameter(PARAM_NAME_1, paramValue)), envVars);
    checkResolvedValue(actualParameters, paramValue, expectedValue);
    // case: several variables
    paramValue = String.format("test/$%s/${%s}/$%s/", ENV_VAR_NAME, ENV_VAR_NAME, ENV_VAR_NAME);
    expectedValue = String.format("test/%s/%s/%s/", ENV_VAR_VALUE, ENV_VAR_VALUE, ENV_VAR_VALUE);
    actualParameters = pipelineRunManager.replaceParametersWithEnvVars(Collections.singletonList(new PipelineRunParameter(PARAM_NAME_1, paramValue)), envVars);
    checkResolvedValue(actualParameters, paramValue, expectedValue);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 5 with PipelineRunParameter

use of com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter in project cloud-pipeline by epam.

the class PipelineRunMapperOld method buildRunParam.

private void buildRunParam(List<PipelineRunParameter> runParams, XContentBuilder jsonBuilder) throws IOException {
    jsonBuilder.startArray("parameters");
    for (PipelineRunParameter runParameter : runParams) {
        jsonBuilder.startObject().field("parameter", runParameter.getName()).field("value", runParameter.getValue()).endObject();
    }
    jsonBuilder.endArray();
}
Also used : PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter)

Aggregations

PipelineRunParameter (com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter)7 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)3 RunStatus (com.epam.pipeline.entity.pipeline.run.RunStatus)3 ArrayList (java.util.ArrayList)3 PipelineRunWithLog (com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog)2 PipelineTask (com.epam.pipeline.entity.pipeline.PipelineTask)2 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)2 RunLog (com.epam.pipeline.entity.pipeline.RunLog)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 LoaderVerificationUtils.verifyPipelineRun (com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyPipelineRun)1 LoaderVerificationUtils.verifyRunInstance (com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyRunInstance)1 MapperVerificationUtils.verifyPipelineRun (com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyPipelineRun)1 EntityContainer (com.epam.pipeline.elasticsearchagent.model.EntityContainer)1 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)1 PipeConfValueVO (com.epam.pipeline.entity.configuration.PipeConfValueVO)1 ExecutionPreferences (com.epam.pipeline.entity.pipeline.run.ExecutionPreferences)1 RestartRun (com.epam.pipeline.entity.pipeline.run.RestartRun)1 RunSid (com.epam.pipeline.entity.pipeline.run.parameter.RunSid)1 AclClass (com.epam.pipeline.entity.security.acl.AclClass)1