public static PipelineScheduleOptions fromJSON(JsonReader jsonReader) { PipelineScheduleOptions model = new PipelineScheduleOptions(); model.shouldPerformMDUBeforeScheduling(jsonReader.optBoolean("update_materials_before_scheduling").orElse(Boolean.TRUE)); jsonReader.readArrayIfPresent("materials", materials -> { List<MaterialForScheduling> materialsForScheduling = new ArrayList<>(); materials.forEach(material -> materialsForScheduling.add(MaterialRevisionRepresenter.fromJSON(new JsonReader(material.getAsJsonObject())))); model.setMaterials(materialsForScheduling); }); model.setEnvironmentVariables(EnvironmentVariableRepresenter.fromJSONArray(jsonReader)); return model; } }
@Override public void build(ScheduleOptions scheduleOptions, HttpOperationResult result, String pipelineName, PipelineScheduleOptions pipelineScheduleOptions, HealthStateType healthStateType) { scheduleOptions.shouldPerformMDUBeforeScheduling(pipelineScheduleOptions.shouldPerformMDUBeforeScheduling()); } }
private PipelineScheduleOptions getScheduleOptions(Request req) { if (StringUtils.isBlank(req.body())) { return new PipelineScheduleOptions(); } GsonTransformer gsonTransformer = GsonTransformer.getInstance(); JsonReader jsonReader = gsonTransformer.jsonReaderFrom(req.body()); return PipelineScheduleOptionsRepresenter.fromJSON(jsonReader); } }
@Override public void build(ScheduleOptions scheduleOptions, HttpOperationResult result, String pipelineName, PipelineScheduleOptions pipelineScheduleOptions, HealthStateType healthStateType) { for (EnvironmentVariableConfig environmentVariable : pipelineScheduleOptions.getPlainTextEnvironmentVariables()) { if (!goConfigService.hasVariableInScope(pipelineName, environmentVariable.getName())) { String variableUnconfiguredMessage = String.format("Variable '%s' has not been configured for pipeline '%s'", environmentVariable.getName(), pipelineName); result.unprocessibleEntity("Request to schedule pipeline rejected", variableUnconfiguredMessage, healthStateType); return; } scheduleOptions.getVariables().add(environmentVariable); } } }
@Override public void build(ScheduleOptions scheduleOptions, HttpOperationResult result, String pipelineName, PipelineScheduleOptions pipelineScheduleOptions, HealthStateType healthStateType) { for (MaterialForScheduling materialForScheduling : pipelineScheduleOptions.getMaterials()) { try { MaterialConfig material = goConfigService.materialForPipelineWithFingerprint(pipelineName, materialForScheduling.getFingerprint()); if (StringUtils.isBlank(materialForScheduling.getRevision())) { result.unprocessibleEntity("Request to schedule pipeline rejected", String.format("Material [%s] has empty revision", materialForScheduling.getFingerprint()), HealthStateType.general(HealthStateScope.GLOBAL)); return; } scheduleOptions.getSpecifiedRevisions().put(material.getPipelineUniqueFingerprint(), materialForScheduling.getRevision()); } catch (Exception e) { result.unprocessibleEntity("Request to schedule pipeline rejected", String.format("Pipeline '%s' does not contain the following material(s): [%s].", pipelineName, materialForScheduling.getFingerprint()), healthStateType); return; } } } }
@Override public void build(ScheduleOptions scheduleOptions, HttpOperationResult result, String pipelineName, PipelineScheduleOptions pipelineScheduleOptions, HealthStateType healthStateType) { for (EnvironmentVariableConfig environmentVariable : pipelineScheduleOptions.getSecureEnvironmentVariables()) { if (!goConfigService.hasVariableInScope(pipelineName, environmentVariable.getName())) { String variableUnconfiguredMessage = String.format("Variable '%s' has not been configured for pipeline '%s'", environmentVariable.getName(), pipelineName); result.unprocessibleEntity("Request to schedule pipeline rejected", variableUnconfiguredMessage, healthStateType); return; } environmentVariable.validate(null); if (!environmentVariable.errors().isEmpty()) { result.unprocessibleEntity("Request to schedule pipeline rejected", environmentVariable.errors().asString(), healthStateType); return; } scheduleOptions.getVariables().add(environmentVariable); } } }