Search in sources :

Example 51 with PipelineRun

use of com.epam.pipeline.entity.pipeline.PipelineRun 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 52 with PipelineRun

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

the class PipelineRunDao method loadPipelineRun.

@Transactional(propagation = Propagation.REQUIRED)
public PipelineRun loadPipelineRun(Long id) {
    List<PipelineRun> items = getJdbcTemplate().query(loadRunByIdQuery, PipelineRunParameters.getExtendedRowMapper(), initTaskStatus.ordinal(), initTaskName, id);
    if (!items.isEmpty()) {
        PipelineRun pipelineRun = items.get(0);
        List<RunSid> runSids = getJdbcTemplate().query(loadRunSidsQuery, PipelineRunParameters.getRunSidsRowMapper(), id);
        pipelineRun.setRunSids(runSids);
        List<Map<String, String>> envVars = getJdbcTemplate().query(loadEnvVarsQuery, PipelineRunParameters.getEnvVarsRowMapper(), pipelineRun.getId());
        pipelineRun.setEnvVars(CollectionUtils.isEmpty(envVars) ? null : envVars.get(0));
        return pipelineRun;
    } else {
        return null;
    }
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) RunSid(com.epam.pipeline.entity.pipeline.run.parameter.RunSid) HashMap(java.util.HashMap) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with PipelineRun

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

the class AutoscaleManager method updatePodStatus.

private void updatePodStatus(Node node, Long id) {
    try {
        LOGGER.debug("Trying to update pod {} status ", id);
        PipelineRun run = pipelineRunManager.loadPipelineRun(id);
        String currentStatus = run.getPodStatus() == null ? "" : run.getPodStatus();
        String status = kubernetesManager.updateStatusWithNodeConditions(new StringBuilder(currentStatus), node);
        if (!status.isEmpty() && !currentStatus.equals(status)) {
            pipelineRunManager.updatePodStatus(id, status);
        }
    } catch (IllegalArgumentException e) {
        LOGGER.debug(e.getMessage(), e);
    }
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun)

Example 54 with PipelineRun

use of com.epam.pipeline.entity.pipeline.PipelineRun 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 55 with PipelineRun

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

the class ClusterManagerImpl method getApiTokenForRun.

private String getApiTokenForRun(String runId) {
    PipelineRun run = pipelineRunManager.loadPipelineRun(Long.valueOf(runId));
    UserContext owner = Optional.ofNullable(authManager.getUserContext()).orElse(userManager.loadUserContext(run.getOwner()));
    return authManager.issueToken(owner, null).getToken();
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) UserContext(com.epam.pipeline.security.UserContext)

Aggregations

PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)88 Test (org.junit.Test)31 Transactional (org.springframework.transaction.annotation.Transactional)29 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)23 EnvVarsBuilderTest (com.epam.pipeline.manager.execution.EnvVarsBuilderTest)22 ArrayList (java.util.ArrayList)18 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)17 Date (java.util.Date)15 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)14 List (java.util.List)14 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)13 Map (java.util.Map)11 LocalDateTime (java.time.LocalDateTime)10 Arrays (java.util.Arrays)10 Collectors (java.util.stream.Collectors)10 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)9 Collections (java.util.Collections)9 HashMap (java.util.HashMap)9 MessageHelper (com.epam.pipeline.common.MessageHelper)8 RunSid (com.epam.pipeline.entity.pipeline.run.parameter.RunSid)8