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());
}
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;
}
}
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);
}
}
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;
}
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();
}
Aggregations