public Map<String, Object> inverseTransform(Object pipeline) { return inverseTransform((Map<String, Object>) pipeline); }
public JsonObject transform(Object maybePipe) { Map<String, Object> map = (Map<String, Object>) maybePipe; for (Map.Entry<String, Object> entry : map.entrySet()) { return transform(entry); } throw new RuntimeException("expected pipeline hash to have 1 item"); }
private void addMaterials(JsonObject pipeline, Map<String, Object> pipeMap) { Object materials = pipeMap.get(YAML_PIPELINE_MATERIALS_FIELD); if (!(materials instanceof Map)) throw new YamlConfigException("expected a hash of pipeline materials"); Map<String, Object> materialsMap = (Map<String, Object>) materials; JsonArray materialsArray = transformMaterials(materialsMap); pipeline.add(JSON_PIPELINE_MATERIALS_FIELD, materialsArray); }
public JsonObject transform(Map.Entry<String, Object> entry) { String pipelineName = entry.getKey(); JsonObject pipeline = new JsonObject(); pipeline.addProperty(JSON_PIPELINE_NAME_FIELD, pipelineName); Map<String, Object> pipeMap = (Map<String, Object>) entry.getValue(); addOptionalString(pipeline, pipeMap, JSON_PIPELINE_GROUP_FIELD, YAML_PIPELINE_GROUP_FIELD); addOptionalString(pipeline, pipeMap, JSON_PIPELINE_TEMPLATE_FIELD, YAML_PIPELINE_TEMPLATE_FIELD); addOptionalString(pipeline, pipeMap, JSON_PIPELINE_LABEL_TEMPLATE_FIELD, YAML_PIPELINE_LABEL_TEMPLATE_FIELD); addOptionalBoolean(pipeline, pipeMap, JSON_PIPELINE_PIPE_LOCKING_FIELD, YAML_PIPELINE_PIPE_LOCKING_FIELD); addOptionalString(pipeline, pipeMap, JSON_PIPELINE_LOCK_BEHAVIOR_FIELD, YAML_PIPELINE_LOCK_BEHAVIOR_FIELD); addOptionalObject(pipeline, pipeMap, JSON_PIPELINE_TRACKING_TOOL_FIELD, YAML_PIPELINE_TRACKING_TOOL_FIELD); addOptionalObject(pipeline, pipeMap, JSON_PIPELINE_MINGLE_FIELD, YAML_PIPELINE_MINGLE_FIELD); addTimer(pipeline, pipeMap); JsonArray jsonEnvVariables = variablesTransform.transform(pipeMap); if (jsonEnvVariables != null && jsonEnvVariables.size() > 0) pipeline.add(JSON_ENV_VAR_FIELD, jsonEnvVariables); addMaterials(pipeline, pipeMap); if (!pipeline.has(JSON_PIPELINE_TEMPLATE_FIELD)) { addStages(pipeline, pipeMap); } JsonArray params = parameterTransform.transform(pipeMap); if (params != null && params.size() > 0) { pipeline.add(YAML_PIPELINE_PARAMETERS_FIELD, params); } return pipeline; }
public Map<String, Object> inverseTransform(Map<String, Object> pipeline) { Map<String, Object> result = new LinkedTreeMap<>(); Map<String, Object> pipelineMap = new LinkedTreeMap<>(); String name = (String) pipeline.get(JSON_PIPELINE_NAME_FIELD); pipelineMap.put(YAML_PIPELINE_GROUP_FIELD, pipeline.get(JSON_PIPELINE_GROUP_FIELD)); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_TEMPLATE_FIELD, YAML_PIPELINE_TEMPLATE_FIELD); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_LABEL_TEMPLATE_FIELD, YAML_PIPELINE_LABEL_TEMPLATE_FIELD); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_PIPE_LOCKING_FIELD, YAML_PIPELINE_PIPE_LOCKING_FIELD); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_LOCK_BEHAVIOR_FIELD, YAML_PIPELINE_LOCK_BEHAVIOR_FIELD); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_TRACKING_TOOL_FIELD, YAML_PIPELINE_TRACKING_TOOL_FIELD); addInverseTimer(pipelineMap, pipeline); Map<String, Object> yamlEnvVariables = variablesTransform.inverseTransform((List<Map<String, Object>>) pipeline.get(JSON_ENV_VAR_FIELD)); if (yamlEnvVariables != null && yamlEnvVariables.size() > 0) pipelineMap.putAll(yamlEnvVariables); addInverseMaterials(pipelineMap, (List<Map<String, Object>>) pipeline.get(JSON_PIPELINE_MATERIALS_FIELD)); if (!pipelineMap.containsKey(YAML_PIPELINE_TEMPLATE_FIELD)) { addInverseStages(pipelineMap, (List<Map<String, Object>>) pipeline.get(JSON_PIPELINE_STAGES_FIELD)); } Map<String, Object> params = parameterTransform.inverseTransform((List<Map<String, Object>>) pipeline.get("parameters")); if (params != null && !params.isEmpty()) { pipelineMap.putAll(params); } result.put(name, pipelineMap); return result; }
@Before public void SetUp() { materialTransform = mock(MaterialTransform.class); stageTransform = mock(StageTransform.class); environmentTransform = mock(EnvironmentVariablesTransform.class); ParameterTransform parameterTransform = mock(ParameterTransform.class); parser = new PipelineTransform(materialTransform, stageTransform, environmentTransform, parameterTransform); yaml = new Yaml(); }
@Test public void shouldPreserveOrderOfPipelines() throws IOException { MaterialTransform materialTransform = mock(MaterialTransform.class); StageTransform stageTransform = mock(StageTransform.class); EnvironmentVariablesTransform environmentTransform = mock(EnvironmentVariablesTransform.class); ParameterTransform parameterTransform = mock(ParameterTransform.class); pipelineTransform = new PipelineTransform(materialTransform, stageTransform, environmentTransform, parameterTransform); rootTransform = new RootTransform(pipelineTransform, environmentsTransform); JsonConfigCollection collection = readRootYaml("pipeline_order"); JsonArray pipelines = collection.getJsonObject().get("pipelines").getAsJsonArray(); assertThat(pipelines.get(0).getAsJsonObject().get("name").getAsString(), is("pipe1")); assertThat(pipelines.get(1).getAsJsonObject().get("name").getAsString(), is("pipe2")); assertThat(pipelines.get(2).getAsJsonObject().get("name").getAsString(), is("pipe3")); }
public String inverseTransformPipeline(Map<String, Object> pipeline) { Map<String, Object> result = new LinkedTreeMap<>(); result.put("format_version", 3); result.put("pipelines", pipelineTransform.inverseTransform(pipeline)); return YamlUtils.dump(result); }
for (Map.Entry<String, Object> pipe : pipelines.entrySet()) { try { JsonElement jsonPipeline = pipelineTransform.transform(pipe); partialConfig.addPipeline(jsonPipeline, location); } catch (Exception ex) {
public RootTransform() { EnvironmentVariablesTransform environmentVarsTransform = new EnvironmentVariablesTransform(); MaterialTransform material = new MaterialTransform(); ParameterTransform parameterTransform = new ParameterTransform(); JobTransform job = new JobTransform(environmentVarsTransform, new TaskTransform()); StageTransform stage = new StageTransform(environmentVarsTransform, job); this.pipelineTransform = new PipelineTransform(material, stage, environmentVarsTransform, parameterTransform); this.environmentsTransform = new EnvironmentsTransform(environmentVarsTransform); }
private void testInverseTransform(String caseFile, String expectedFile) throws IOException { String expectedObject = loadString("parts/" + expectedFile + ".yaml"); Map<String, Object> actual = parser.inverseTransform(readJsonGson("parts/" + caseFile + ".json")); assertYamlEquivalent(expectedObject, YamlUtils.dump(actual)); } }
private void testTransform(String caseFile, String expectedFile) throws IOException { JsonObject expectedObject = (JsonObject) readJsonObject("parts/" + expectedFile + ".json"); JsonObject jsonObject = parser.transform(readYamlObject("parts/" + caseFile + ".yaml")); assertThat(jsonObject, is(new JsonObjectMatcher(expectedObject))); }