protected long limitInMb() { ServerConfig serverConfig = goConfigService.serverConfig(); return serverConfig.isArtifactPurgingAllowed() ? new Double(serverConfig.getPurgeStart() * GoConstants.MEGABYTES_IN_GIGABYTE).longValue() : Integer.MAX_VALUE; }
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 shouldAllowArtifactPurgingIfPurgeParametersAreDefined() { another = new ServerConfig("artifacts", new SecurityConfig(), 10.0, 20.0); assertThat(another.isArtifactPurgingAllowed(), is(true)); another = new ServerConfig("artifacts", new SecurityConfig(), null, 20.0); assertThat(another.isArtifactPurgingAllowed(), is(false)); another = new ServerConfig("artifacts", new SecurityConfig(), 10.0, null); assertThat(another.isArtifactPurgingAllowed(), is(false)); another = new ServerConfig("artifacts", new SecurityConfig(), null, null); assertThat(another.isArtifactPurgingAllowed(), is(false)); }