Search in sources :

Example 1 with MaterialForScheduling

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;
}
Also used : MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) ArrayList(java.util.ArrayList) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Example 2 with MaterialForScheduling

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());
}
Also used : MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 3 with MaterialForScheduling

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));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) GoCipher(com.thoughtworks.go.security.GoCipher) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 4 with MaterialForScheduling

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());
}
Also used : MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 5 with MaterialForScheduling

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));
}
Also used : MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

MaterialForScheduling (com.thoughtworks.go.server.domain.MaterialForScheduling)6 PipelineScheduleOptions (com.thoughtworks.go.server.domain.PipelineScheduleOptions)6 Test (org.junit.Test)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)2 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)1 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 MaterialUpdateSuccessfulMessage (com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage)1 ArrayList (java.util.ArrayList)1