Search in sources :

Example 21 with ServerHealthState

use of com.thoughtworks.go.serverhealth.ServerHealthState in project gocd by gocd.

the class CachedGoConfig method saveConfigError.

private synchronized void saveConfigError(Exception e) {
    this.lastException = e;
    ServerHealthState state = ServerHealthState.error(INVALID_CRUISE_CONFIG_XML, GoConfigValidity.invalid(e).errorMessage(), HealthStateType.invalidConfig());
    serverHealthService.update(state);
}
Also used : ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 22 with ServerHealthState

use of com.thoughtworks.go.serverhealth.ServerHealthState in project gocd by gocd.

the class ScheduledPipelineLoaderIntegrationTest method shouldSetAServerHealthMessageWhenMaterialForPipelineWithBuildCauseIsNotFound.

@Test
public void shouldSetAServerHealthMessageWhenMaterialForPipelineWithBuildCauseIsNotFound() throws IllegalArtifactLocationException, IOException {
    PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("last", new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    pipelineConfig.materialConfigs().clear();
    SvnMaterialConfig onDirOne = MaterialConfigsMother.svnMaterialConfig("google.com", "dirOne", "loser", "boozer", false, "**/*.html");
    final P4MaterialConfig onDirTwo = MaterialConfigsMother.p4MaterialConfig("host:987654321", "zoozer", "secret", "through-the-window", true);
    onDirTwo.setConfigAttributes(Collections.singletonMap(ScmMaterialConfig.FOLDER, "dirTwo"));
    pipelineConfig.addMaterialConfig(onDirOne);
    pipelineConfig.addMaterialConfig(onDirTwo);
    configHelper.addPipeline(pipelineConfig);
    Pipeline building = PipelineMother.building(pipelineConfig);
    final Pipeline pipeline = dbHelper.savePipelineWithMaterials(building);
    CruiseConfig cruiseConfig = configHelper.currentConfig();
    PipelineConfig cfg = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("last"));
    cfg.removeMaterialConfig(cfg.materialConfigs().get(1));
    configHelper.writeConfigFile(cruiseConfig);
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPipeline("last")).size(), is(0));
    final long jobId = pipeline.getStages().get(0).getJobInstances().get(0).getId();
    Date currentTime = new Date(System.currentTimeMillis() - 1);
    Pipeline loadedPipeline = (Pipeline) transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            Pipeline loadedPipeline = null;
            try {
                loadedPipeline = loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
                fail("should not have loaded pipeline with build-cause as one of the necessary materials was not found");
            } catch (Exception e) {
                assertThat(e, is(instanceOf(StaleMaterialsOnBuildCause.class)));
                assertThat(e.getMessage(), is("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config."));
            }
            return loadedPipeline;
        }
    });
    assertThat(loadedPipeline, is(nullValue()));
    JobInstance reloadedJobInstance = jobInstanceService.buildById(jobId);
    assertThat(reloadedJobInstance.getState(), is(JobState.Completed));
    assertThat(reloadedJobInstance.getResult(), is(JobResult.Failed));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forJob("last", "stage", "job-one")).size(), is(1));
    ServerHealthState error = serverHealthService.filterByScope(HealthStateScope.forJob("last", "stage", "job-one")).get(0);
    assertThat(error, is(ServerHealthState.error("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config.", "Job for pipeline 'last/" + pipeline.getCounter() + "/stage/1/job-one' has been failed as one or more material configurations were either changed or removed.", HealthStateType.general(HealthStateScope.forJob("last", "stage", "job-one")))));
    DateTime expiryTime = (DateTime) ReflectionUtil.getField(error, "expiryTime");
    assertThat(expiryTime.toDate().after(currentTime), is(true));
    assertThat(expiryTime.toDate().before(new Date(System.currentTimeMillis() + 5 * 60 * 1000 + 1)), is(true));
    String logText = FileUtils.readFileToString(consoleService.consoleLogArtifact(reloadedJobInstance.getIdentifier()), UTF_8);
    assertThat(logText, containsString("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config."));
    assertThat(logText, containsString("Job for pipeline 'last/" + pipeline.getCounter() + "/stage/1/job-one' has been failed as one or more material configurations were either changed or removed."));
}
Also used : StaleMaterialsOnBuildCause(com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause) TransactionStatus(org.springframework.transaction.TransactionStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) Date(java.util.Date) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) TransactionCallback(org.springframework.transaction.support.TransactionCallback) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.Test)

Example 23 with ServerHealthState

use of com.thoughtworks.go.serverhealth.ServerHealthState in project gocd by gocd.

the class PipelineSchedulerIntegrationTest method shouldRemoveAllErrorLogsForPipelineIfSchedulingSucceeded.

@Test
public void shouldRemoveAllErrorLogsForPipelineIfSchedulingSucceeded() throws Exception {
    serverHealthService.update(ServerHealthState.error("failed to connect to scm", "failed to connect to scm", HealthStateType.general(HealthStateScope.forPipeline(PIPELINE_MINGLE))));
    serverHealthService.update(ServerHealthState.error("failed to connect to scm", "failed to connect to scm", HealthStateType.artifactsDiskFull()));
    ServerHealthState serverHealthState = scheduleHelper.manuallySchedulePipelineWithRealMaterials(PIPELINE_MINGLE, cruise);
    assertThat(serverHealthState.isSuccess(), is(true));
    assertCurrentErrorLogNumberIs(PIPELINE_MINGLE, 0);
}
Also used : ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 24 with ServerHealthState

use of com.thoughtworks.go.serverhealth.ServerHealthState in project gocd by gocd.

the class GoPartialConfigIntegrationTest method shouldValidateAndMergeJustTheChangedPartialAlongWithAllValidPartialsIfValidationOfAllKnownPartialsFail.

@Test
public void shouldValidateAndMergeJustTheChangedPartialAlongWithAllValidPartialsIfValidationOfAllKnownPartialsFail() {
    goPartialConfig.onSuccessPartialConfig(repoConfig1, PartialConfigMother.withPipeline("p1_repo1", new RepoConfigOrigin(repoConfig1, "1")));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString("p1_repo1")), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1.getMaterialConfig().getFingerprint())).isEmpty(), is(true));
    final String invalidPipelineInPartial = "p1_repo1_invalid";
    PartialConfig invalidPartial = PartialConfigMother.invalidPartial(invalidPipelineInPartial, new RepoConfigOrigin(repoConfig1, "2"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, invalidPartial);
    assertThat(findPartial(invalidPipelineInPartial, cachedGoPartials.lastValidPartials()), is(nullValue()));
    assertThat(findPartial(invalidPipelineInPartial, cachedGoPartials.lastKnownPartials()), is(invalidPartial));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(invalidPipelineInPartial)), is(false));
    List<ServerHealthState> serverHealthStatesForRepo1 = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1));
    assertThat(serverHealthStatesForRepo1.isEmpty(), is(false));
    assertThat(serverHealthStatesForRepo1.get(0).getLogLevel(), is(HealthStateLevel.ERROR));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, PartialConfigMother.withPipeline("p2_repo2", new RepoConfigOrigin(repoConfig2, "1")));
    assertThat(findPartial(invalidPipelineInPartial, cachedGoPartials.lastValidPartials()), is(nullValue()));
    assertThat(findPartial(invalidPipelineInPartial, cachedGoPartials.lastKnownPartials()), is(invalidPartial));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString("p1_repo1")), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString("p2_repo2")), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(invalidPipelineInPartial)), is(false));
    serverHealthStatesForRepo1 = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1));
    assertThat(serverHealthStatesForRepo1.isEmpty(), is(false));
    assertThat(serverHealthStatesForRepo1.get(0).getLogLevel(), is(HealthStateLevel.ERROR));
    List<ServerHealthState> serverHealthStatesForRepo2 = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2));
    assertThat(serverHealthStatesForRepo2.isEmpty(), is(true));
}
Also used : RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.Test)

Example 25 with ServerHealthState

use of com.thoughtworks.go.serverhealth.ServerHealthState in project gocd by gocd.

the class GoPartialConfigIntegrationTest method shouldNotSaveConfigWhenANewInValidPartialGetsAdded.

@Test
public void shouldNotSaveConfigWhenANewInValidPartialGetsAdded() {
    PartialConfig invalidPartial = PartialConfigMother.invalidPartial("p1");
    invalidPartial.setOrigins(new RepoConfigOrigin(repoConfig1, "sha-2"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, invalidPartial);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString("p1")), is(false));
    List<ServerHealthState> serverHealthStates = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1));
    assertThat(serverHealthStates.isEmpty(), is(false));
    assertThat(serverHealthStates.get(0).getLogLevel(), is(HealthStateLevel.ERROR));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.Test)

Aggregations

ServerHealthState (com.thoughtworks.go.serverhealth.ServerHealthState)25 Test (org.junit.Test)10 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)3 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)3 Material (com.thoughtworks.go.domain.materials.Material)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)2 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)2 StaleMaterialsOnBuildCause (com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause)2 Gson (com.google.gson.Gson)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 TimerConfig (com.thoughtworks.go.config.TimerConfig)1 Materials (com.thoughtworks.go.config.materials.Materials)1 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)1 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1