void deleteOldArtifacts() { ServerConfig serverConfig = goConfigService.serverConfig(); Double requiredSpaceInGb = serverConfig.getPurgeUpto(); if (serverConfig.isArtifactPurgingAllowed()) { double requiredSpace = requiredSpaceInGb * GoConstants.GIGA_BYTE; LOGGER.info("Clearing old artifacts as the disk space is low. Current space: '{}'. Need to clear till we hit: '{}'.", availableSpace(), requiredSpace); List<Stage> stages; int numberOfStagesPurged = 0; do { configDbStateRepository.flushConfigState(); stages = stageService.oldestStagesWithDeletableArtifacts(); for (Stage stage : stages) { if (availableSpace() > requiredSpace) { break; } numberOfStagesPurged++; artifactService.purgeArtifactsForStage(stage); } } while ((availableSpace() < requiredSpace) && !stages.isEmpty()); if (availableSpace() < requiredSpace) { LOGGER.warn("Ran out of stages to clear artifacts from but the disk space is still low"); } LOGGER.info("Finished clearing old artifacts. Deleted artifacts for '{}' stages. Current space: '{}'", numberOfStagesPurged, availableSpace()); } }
@Test public void shouldAllowNullPurgeStartAndEnd() { String content = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<server artifactsdir='artifacts'>" + "</server></cruise>"; CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(content).config; assertThat(cruiseConfig.server().getPurgeStart(), is(nullValue())); assertThat(cruiseConfig.server().getPurgeUpto(), is(nullValue())); }
@Test public void shouldAllowPurgeStartAndPurgeUptoAttributes() { String content = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<server artifactsdir='artifacts' purgeStart='1' purgeUpto='3'>" + "</server></cruise>"; CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(content).config; assertThat(cruiseConfig.server().getPurgeStart(), is(1.0)); assertThat(cruiseConfig.server().getPurgeUpto(), is(3.0)); }
@Test public void shouldAllowDoublePurgeStartAndPurgeUptoAttributes() { String content = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<server artifactsdir='artifacts' purgeStart='1.2' purgeUpto='3.4'>" + "</server></cruise>"; CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(content).config; assertThat(cruiseConfig.server().getPurgeStart(), is(1.2)); assertThat(cruiseConfig.server().getPurgeUpto(), is(3.4)); }