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