use of com.thoughtworks.go.server.domain.MaterialForScheduling in project gocd by gocd.
the class PipelineScheduleOptionsRepresenter method fromJSON.
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);
});
jsonReader.readArrayIfPresent("environment_variables", environmentVariables -> {
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
environmentVariables.forEach(variable -> variables.add(EnvrionmentVariableRepresenter.fromJSON(new JsonReader(variable.getAsJsonObject()))));
model.setEnvironmentVariables(variables);
});
return model;
}
use of com.thoughtworks.go.server.domain.MaterialForScheduling in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldNotPerformMDUIfScheduleOptionsIsSetToDisallowMDU.
@Test
public void shouldNotPerformMDUIfScheduleOptionsIsSetToDisallowMDU() throws IOException {
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
pipelineScheduleOptions.shouldPerformMDUBeforeScheduling(false);
String peggedRevision = "s2";
MaterialForScheduling material = new MaterialForScheduling(pipelineConfig.materialConfigs().first().getFingerprint(), peggedRevision);
pipelineScheduleOptions.getMaterials().add(material);
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(true));
assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", pipelineName)));
assertThat(result.httpCode(), is(202));
assertThat(materialUpdateStatusNotifier.hasListenerFor(pipelineConfig), is(false));
BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
assertNotNull(buildCause);
assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername())));
assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s2"));
assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
assertTrue(buildCause.getVariables().isEmpty());
}
use of com.thoughtworks.go.server.domain.MaterialForScheduling in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldReturnErrorIfThePipelineBeingScheduledDoesnotExistAndHasMaterialsSetInRequest.
@Test
public void shouldReturnErrorIfThePipelineBeingScheduledDoesnotExistAndHasMaterialsSetInRequest() {
String pipelineName = "does-not-exist";
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
pipelineScheduleOptions.getMaterials().add(new MaterialForScheduling("non-existant-material", "r1"));
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "overridden_value", false));
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "overridden_secure_value", true));
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(false));
assertThat(result.fullMessage(), is("Pipeline 'does-not-exist' not found."));
assertThat(result.httpCode(), is(404));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
use of com.thoughtworks.go.server.domain.MaterialForScheduling in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithTheProvidedMaterialRevisions.
@Test
public void shouldScheduleAPipelineWithTheProvidedMaterialRevisions() throws IOException {
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
String peggedRevision = "s2";
MaterialForScheduling material = new MaterialForScheduling(pipelineConfig.materialConfigs().first().getFingerprint(), peggedRevision);
pipelineScheduleOptions.getMaterials().add(material);
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(true));
assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", pipelineName)));
assertThat(result.httpCode(), is(202));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(true));
materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
assertNotNull(buildCause);
assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername())));
assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s2"));
assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
assertTrue(buildCause.getVariables().isEmpty());
}
use of com.thoughtworks.go.server.domain.MaterialForScheduling in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldNotScheduleAPipelineIfTheProvidedMaterialRevisionIsNotKnownAndScheduleOptionSuggestsNoMDU.
@Test
public void shouldNotScheduleAPipelineIfTheProvidedMaterialRevisionIsNotKnownAndScheduleOptionSuggestsNoMDU() throws IOException {
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
pipelineScheduleOptions.shouldPerformMDUBeforeScheduling(false);
String peggedRevision = "unseen-revision";
String fingerprint = pipelineConfig.materialConfigs().first().getFingerprint();
MaterialForScheduling material = new MaterialForScheduling(fingerprint, peggedRevision);
pipelineScheduleOptions.getMaterials().add(material);
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(false));
assertThat(result.fullMessage(), is(String.format("Error while scheduling pipeline: %s { Unable to find revision [%s] for material [%s] }", pipelineName, peggedRevision, new MaterialConfigConverter().toMaterial(pipelineConfig.materialConfigs().first()))));
assertThat(result.httpCode(), is(422));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
Aggregations