public static HealthStateType forbiddenForGroup(String groupName) { return new HealthStateType("FORBIDDEN", 403, HealthStateScope.forGroup(groupName), null); }
for (PipelineConfig pc : config.getAllPipelineConfigs()) { for (MaterialConfig mc : pc.materialConfigs()) { String scope = HealthStateScope.forMaterialConfig(mc).getScope(); if (scope.equals(this.scope)) { pipelineNames.add(pc.name().toString()); for (PipelineConfig pc : config.getAllPipelineConfigs()) { for (MaterialConfig mc : pc.materialConfigs()) { String scope = HealthStateScope.forMaterialConfigUpdate(mc).getScope(); if (scope.equals(this.scope)) { pipelineNames.add(pc.name().toString());
public static HealthStateType forbiddenForPipeline(String pipelineName) { return new HealthStateType("FORBIDDEN", 403, HealthStateScope.forPipeline(pipelineName), null); }
public boolean isRemovedFromConfig(CruiseConfig cruiseConfig, String materialScope) { for (ConfigRepoConfig configRepoConfig : cruiseConfig.getConfigRepos()) { if (HealthStateScope.forPartialConfigRepo(configRepoConfig).getScope().equals(materialScope)) { return false; } } return true; } },
public boolean isRemovedFromConfig(CruiseConfig cruiseConfig, String materialScope) { for (MaterialConfig materialConfig : cruiseConfig.getAllUniqueMaterialsOfPipelinesAndConfigRepos()) { if (HealthStateScope.forMaterialConfig(materialConfig).getScope().equals(materialScope)) { return false; } } return true; } },
public boolean isRemovedFromConfig(CruiseConfig cruiseConfig, String materialScope) { for (MaterialConfig materialConfig : cruiseConfig.getAllUniqueMaterialsOfPipelinesAndConfigRepos()) { if (HealthStateScope.forMaterialConfigUpdate(materialConfig).getScope().equals(materialScope)) { return false; } } return true; } },
@Test public void shouldRemoveScopeWhenStageIsRemovedFromConfig() throws Exception { CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz"); assertThat(HealthStateScope.forPipeline("fooPipeline").isRemovedFromConfig(config),is(true)); assertThat(HealthStateScope.forPipeline("blahPipeline").isRemovedFromConfig(config),is(false)); assertThat(HealthStateScope.forStage("fooPipeline","blahStage").isRemovedFromConfig(config),is(true)); assertThat(HealthStateScope.forStage("blahPipeline","blahStageRemoved").isRemovedFromConfig(config),is(true)); assertThat(HealthStateScope.forStage("blahPipeline","blahStage").isRemovedFromConfig(config),is(false)); }
private HealthStateType stageScopedHealthState(String pipelineName, String stageName) { return HealthStateType.general(HealthStateScope.forStage(pipelineName, stageName)); }
@Test public void stateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService = new ServerHealthService(); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forPipeline(PIPELINE_NAME)))); assertThat((serverHealthService.logs().get(0)).getPipelineNames(config), equalTo(Collections.singleton(PIPELINE_NAME))); serverHealthService = new ServerHealthService(); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forStage(PIPELINE_NAME, "stage1")))); assertThat((serverHealthService.logs().get(0)).getPipelineNames(config), equalTo(Collections.singleton(PIPELINE_NAME))); serverHealthService = new ServerHealthService(); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forJob(PIPELINE_NAME, "stage1", "job1")))); assertThat((serverHealthService.logs().get(0)).getPipelineNames(config), equalTo(Collections.singleton(PIPELINE_NAME))); }
@Test public void shouldRemoveScopeWhenMaterialIsRemovedFromConfig() throws Exception { HgMaterialConfig hgMaterialConfig = MaterialConfigsMother.hgMaterialConfig(); CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz"); config.pipelineConfigByName(new CaseInsensitiveString("blahPipeline")).addMaterialConfig(hgMaterialConfig); assertThat(HealthStateScope.forMaterialConfig(hgMaterialConfig).isRemovedFromConfig(config),is(false)); assertThat(HealthStateScope.forMaterial(MaterialsMother.svnMaterial("file:///bar")).isRemovedFromConfig(config),is(true)); }
@Test public void shouldUnderstandPluginScope() { HealthStateScope scope = HealthStateScope.aboutPlugin("plugin.one"); assertThat(scope.getScope(), is("plugin.one")); assertThat(scope.getType(), is(HealthStateScope.ScopeType.PLUGIN)); } }
@Before public void setUp() throws Exception { serverHealthService = new ServerHealthService(); globalId = HealthStateType.general(GLOBAL); pipelineId = HealthStateType.general(forPipeline(PIPELINE_NAME)); groupId = HealthStateType.invalidLicense(forGroup("group")); testingClock = new TestingClock(); ServerHealthState.clock = testingClock; }
public PartialConfigParseResult get(String fingerprint) { PartialConfigParseResult result = fingerprintOfPartialToParseResultMap.get(fingerprint); // config repository was never parsed, check if there are any material clone or update related errors if (result == null) { HealthStateScope healthStateScope = HealthStateScope.forMaterialConfig(configRepoService.findByFingerprint(fingerprint).getMaterialConfig()); List<ServerHealthState> serverHealthStates = serverHealthService.filterByScope(healthStateScope); if (!serverHealthStates.isEmpty()) { result = PartialConfigParseResult.parseFailed(null, represent(serverHealthStates.get(0))); } } //config repository was parsed, but does not have merge or clone related errors. if (result != null && result.getLastFailure() == null) { HealthStateScope healthStateScope = HealthStateScope.forPartialConfigRepo(fingerprint); List<ServerHealthState> serverHealthStates = serverHealthService.filterByScope(healthStateScope); if (!serverHealthStates.isEmpty()) { result.setException(represent(serverHealthStates.get(0))); //clear out the good modification, in case good modification is same as of latest parsed modification if (result.getLatestParsedModification().equals(result.getGoodModification())) { result.setGoodModification(null); result.setPartialConfig(null); } } } return result; }
@Test public void shouldNotRemoveScopeWhenMaterialBelongsToConfigRepoMaterial() throws Exception { HgMaterialConfig hgMaterialConfig = MaterialConfigsMother.hgMaterialConfig(); CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz"); config.getConfigRepos().add(new ConfigRepoConfig(hgMaterialConfig, "id1", "foo")); assertThat(HealthStateScope.forMaterialConfig(hgMaterialConfig).isRemovedFromConfig(config),is(false)); }
@Test public void shouldRemoveErrorLogWhenCorrespondingMaterialIsMissing() throws Exception { serverHealthService.update(ServerHealthState.error("hg-message", "description", HealthStateType.general(forMaterial(MaterialsMother.hgMaterial())))); SvnMaterialConfig svnMaterialConfig = MaterialConfigsMother.svnMaterialConfig(); serverHealthService.update(ServerHealthState.error("svn-message", "description", HealthStateType.general(forMaterialConfig(svnMaterialConfig)))); CruiseConfig cruiseConfig = new BasicCruiseConfig(); cruiseConfig.addPipeline("defaultGroup", new PipelineConfig(new CaseInsensitiveString("dev"), new MaterialConfigs(svnMaterialConfig), new StageConfig(new CaseInsensitiveString("first"), new JobConfigs()))); serverHealthService.purgeStaleHealthMessages(cruiseConfig); assertThat(serverHealthService.logs().size(), is(1)); }
@Test public void shouldRemoveScopeWhenJobIsRemovedFromConfig() throws Exception { CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz"); assertThat(HealthStateScope.forJob("fooPipeline","blahStage", "barJob").isRemovedFromConfig(config),is(true)); assertThat(HealthStateScope.forJob("blahPipeline", "blahStage", "blahJob").isRemovedFromConfig(config),is(false)); }
@Override public void onEntityConfigChange(PipelineConfig pipelineConfig) { for (ServerHealthState state : serverHealthService.logs()) { HealthStateScope currentScope = state.getType().getScope(); if (currentScope.isForJob()) { String[] split = currentScope.getScope().split("/"); if (split.length > 0 && new CaseInsensitiveString(split[0]).equals(pipelineConfig.name())) { serverHealthService.removeByScope(currentScope); } } } } }
@Test public void shouldHaveDifferentScopeForDifferentMaterials() throws Exception { HealthStateScope scope1 = HealthStateScope.forMaterial(MATERIAL1); HealthStateScope scope2 = HealthStateScope.forMaterial(MATERIAL2); assertThat(scope1, not(scope2)); }
@Test public void shouldNotRemoveScopeWhenMaterialUpdateBelongsToConfigRepoMaterial() throws Exception { HgMaterialConfig hgMaterialConfig = MaterialConfigsMother.hgMaterialConfig(); CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz"); config.getConfigRepos().add(new ConfigRepoConfig(hgMaterialConfig, "id1", "foo")); assertThat(HealthStateScope.forMaterialConfigUpdate(hgMaterialConfig).isRemovedFromConfig(config),is(false)); }
private Set<HealthStateScope> toHealthStateScopes(Set<MaterialConfig> materialConfigs) { Set<HealthStateScope> scopes = new HashSet<>(); for (MaterialConfig materialConfig : materialConfigs) { scopes.add(HealthStateScope.forMaterialConfig(materialConfig)); } return scopes; }