Search in sources :

Example 1 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.

the class PipelineOperationsControllerV1Delegate method getScheduleOptions.

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

Example 2 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions 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 3 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.

the class ScheduleOptionsBuilder method build.

public ScheduleOptions build(HttpOperationResult result, String pipelineName, PipelineScheduleOptions pipelineScheduleOptions) {
    ScheduleOptions scheduleOptions = new ScheduleOptions();
    HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forPipeline(pipelineName));
    if (!goConfigService.hasPipelineNamed(new CaseInsensitiveString(pipelineName))) {
        result.notFound(String.format("Pipeline '%s' not found.", pipelineName), "", healthStateType);
        return null;
    }
    for (Builder builder : builders) {
        if (result.canContinue())
            builder.build(scheduleOptions, result, pipelineName, pipelineScheduleOptions, healthStateType);
    }
    return scheduleOptions;
}
Also used : PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 4 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.

the class PipelineTriggerService method schedule.

public void schedule(String pipelineName, PipelineScheduleOptions pipelineScheduleOptions, Username username, final HttpOperationResult result) {
    LOGGER.info("[Pipeline Schedule] [Requested] Manual trigger of pipeline '{}' requested by {}", pipelineName, CaseInsensitiveString.str(username.getUsername()));
    ScheduleOptions scheduleOptions = new ScheduleOptionsBuilder(goConfigService).build(result, pipelineName, pipelineScheduleOptions);
    if (result.canContinue()) {
        LOGGER.info("[Pipeline Schedule] [Accepted] Manual trigger of pipeline '{}' accepted for user {}", pipelineName, CaseInsensitiveString.str(username.getUsername()));
        buildCauseProducerService.manualSchedulePipeline(username, new CaseInsensitiveString(pipelineName), scheduleOptions, result);
        LOGGER.info("[Pipeline Schedule] [Processed] Manual trigger of pipeline '{}' processed with result '{}'", pipelineName, result.getServerHealthState());
    }
}
Also used : ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) ScheduleOptionsBuilder(com.thoughtworks.go.server.service.builders.ScheduleOptionsBuilder) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 5 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions 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)

Aggregations

PipelineScheduleOptions (com.thoughtworks.go.server.domain.PipelineScheduleOptions)18 Test (org.junit.Test)14 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)9 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)6 GoCipher (com.thoughtworks.go.security.GoCipher)6 MaterialForScheduling (com.thoughtworks.go.server.domain.MaterialForScheduling)6 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)5 MaterialUpdateSuccessfulMessage (com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 JsonReader (com.thoughtworks.go.api.representers.JsonReader)2 EnvironmentVariable (com.thoughtworks.go.domain.EnvironmentVariable)2 Username (com.thoughtworks.go.server.domain.Username)2 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)2 Predicate (org.apache.commons.collections.Predicate)2 GsonTransformer (com.thoughtworks.go.api.util.GsonTransformer)1 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)1 ScheduleOptionsBuilder (com.thoughtworks.go.server.service.builders.ScheduleOptionsBuilder)1 HealthStateType (com.thoughtworks.go.serverhealth.HealthStateType)1 ArrayList (java.util.ArrayList)1