Search in sources :

Example 1 with MaterialFingerprintTag

use of com.thoughtworks.go.util.MaterialFingerprintTag in project gocd by gocd.

the class GitRepoContainingSubmodule method modifyOneFileInSubmoduleAndUpdateMainRepo.

public List<Modification> modifyOneFileInSubmoduleAndUpdateMainRepo(File remoteSubmoduleRepoLocation, String submoduleNameInRepo, String fileName, String newContentOfFile) throws Exception {
    String comment = "Changed file: " + fileName + " in submodule: " + remoteSubmoduleRepoLocation;
    changeFile(remoteSubmoduleRepoLocation, fileName, newContentOfFile);
    checkInOneFile(remoteSubmoduleRepoLocation, new File(fileName), comment);
    CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("pull").withWorkingDir(new File(remoteRepoDir, submoduleNameInRepo)).runOrBomb(new MaterialFingerprintTag(null));
    checkInOneFile(remoteRepoDir, new File(submoduleNameInRepo), comment);
    return latestModification();
}
Also used : MaterialFingerprintTag(com.thoughtworks.go.util.MaterialFingerprintTag) File(java.io.File)

Example 2 with MaterialFingerprintTag

use of com.thoughtworks.go.util.MaterialFingerprintTag in project gocd by gocd.

the class MaterialUpdateServiceTest method shouldUpdateServerHealthMessageWhenHung.

@Test
void shouldUpdateServerHealthMessageWhenHung() {
    // given
    service = spy(service);
    systemEnvironment.set(SystemEnvironment.MATERIAL_UPDATE_INACTIVE_TIMEOUT, 1);
    ProcessManager processManager = mock(ProcessManager.class);
    Material material = mock(Material.class);
    service.updateMaterial(material);
    when(service.getProcessManager()).thenReturn(processManager);
    when(material.getFingerprint()).thenReturn("fingerprint");
    when(material.getUriForDisplay()).thenReturn("uri");
    when(material.getLongDescription()).thenReturn("details to uniquely identify a material");
    when(material.isAutoUpdate()).thenReturn(true);
    when(processManager.getIdleTimeFor(new MaterialFingerprintTag("fingerprint"))).thenReturn(60010L);
    // when
    service.updateMaterial(material);
    // then
    verify(serverHealthService).removeByScope(HealthStateScope.forMaterialUpdate(material));
    ArgumentCaptor<ServerHealthState> argumentCaptor = ArgumentCaptor.forClass(ServerHealthState.class);
    verify(serverHealthService).update(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getMessage()).isEqualTo("Material update for uri hung:");
    assertThat(argumentCaptor.getValue().getDescription()).isEqualTo("Material update is currently running but has not shown any activity in the last 1 minute(s). This may be hung. Details - details to uniquely identify a material");
    assertThat(argumentCaptor.getValue().getType()).isEqualTo(HealthStateType.general(HealthStateScope.forMaterialUpdate(material)));
}
Also used : MaterialFingerprintTag(com.thoughtworks.go.util.MaterialFingerprintTag) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialsMother.gitMaterial(com.thoughtworks.go.helper.MaterialsMother.gitMaterial) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) ProcessManager(com.thoughtworks.go.util.ProcessManager) Test(org.junit.jupiter.api.Test)

Example 3 with MaterialFingerprintTag

use of com.thoughtworks.go.util.MaterialFingerprintTag in project gocd by gocd.

the class P4CommandTestBase method shouldBombForNonZeroReturnCode.

@Test
void shouldBombForNonZeroReturnCode() {
    ProcessOutputStreamConsumer outputStreamConsumer = Mockito.mock(ProcessOutputStreamConsumer.class);
    CommandLine line = Mockito.mock(CommandLine.class);
    when(line.run(outputStreamConsumer, new MaterialFingerprintTag(null), "foo")).thenReturn(1);
    try {
        p4.execute(line, "foo", outputStreamConsumer, true);
        fail("did't bomb for non zero return code");
    } catch (Exception ignored) {
    }
    verify(line).run(outputStreamConsumer, new MaterialFingerprintTag(null), "foo");
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) MaterialFingerprintTag(com.thoughtworks.go.util.MaterialFingerprintTag) ProcessOutputStreamConsumer(com.thoughtworks.go.util.command.ProcessOutputStreamConsumer) Test(org.junit.jupiter.api.Test)

Example 4 with MaterialFingerprintTag

use of com.thoughtworks.go.util.MaterialFingerprintTag in project gocd by gocd.

the class MaterialUpdateService method updateMaterial.

public boolean updateMaterial(Material material) {
    Date inProgressSince = inProgress.putIfAbsent(material, new Date());
    if (inProgressSince == null || !material.isAutoUpdate()) {
        LOGGER.debug("[Material Update] Starting update of material {}", material);
        try {
            long trackingId = mduPerformanceLogger.materialSentToUpdateQueue(material);
            queueFor(material).post(new MaterialUpdateMessage(material, trackingId));
            return true;
        } catch (RuntimeException e) {
            inProgress.remove(material);
            throw e;
        }
    } else {
        LOGGER.warn("[Material Update] Skipping update of material {} which has been in-progress since {}", material, inProgressSince);
        long idleTime = getProcessManager().getIdleTimeFor(new MaterialFingerprintTag(material.getFingerprint()));
        if (idleTime > getMaterialUpdateInActiveTimeoutInMillis()) {
            HealthStateScope scope = HealthStateScope.forMaterialUpdate(material);
            serverHealthService.removeByScope(scope);
            serverHealthService.update(warning("Material update for " + material.getUriForDisplay() + " hung:", "Material update is currently running but has not shown any activity in the last " + idleTime / 60000 + " minute(s). This may be hung. Details - " + material.getLongDescription(), general(scope)));
        }
        return false;
    }
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) MaterialFingerprintTag(com.thoughtworks.go.util.MaterialFingerprintTag)

Aggregations

MaterialFingerprintTag (com.thoughtworks.go.util.MaterialFingerprintTag)4 Test (org.junit.jupiter.api.Test)2 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 Material (com.thoughtworks.go.domain.materials.Material)1 MaterialsMother.gitMaterial (com.thoughtworks.go.helper.MaterialsMother.gitMaterial)1 HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)1 ServerHealthState (com.thoughtworks.go.serverhealth.ServerHealthState)1 ProcessManager (com.thoughtworks.go.util.ProcessManager)1 CommandLine (com.thoughtworks.go.util.command.CommandLine)1 ProcessOutputStreamConsumer (com.thoughtworks.go.util.command.ProcessOutputStreamConsumer)1 File (java.io.File)1