Search in sources :

Example 31 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class BuildTaskEndpointImpl method buildTaskCompleted.

@Override
public Response buildTaskCompleted(String buildId, BuildResultRest buildResult) throws InvalidEntityException {
    // TODO set MDC from request headers instead of business data
    // logger.debug("Received task completed notification for coordinating task id [{}].", buildId);
    // BuildExecutionConfigurationRest buildExecutionConfiguration = buildResult.getBuildExecutionConfiguration();
    // buildResult.getRepositoryManagerResult().getBuildContentId();
    // if (buildExecutionConfiguration == null) {
    // logger.error("Missing buildExecutionConfiguration in buildResult for buildTaskId [{}].", buildId);
    // throw new CoreException("Missing buildExecutionConfiguration in buildResult for buildTaskId " + buildId);
    // }
    // MDCUtils.addContext(buildExecutionConfiguration.getBuildContentId(),
    // buildExecutionConfiguration.isTempBuild(), systemConfig.getTemporaryBuildExpireDate());
    logger.info("Received build task completed notification for id {}.", buildId);
    ValidationBuilder.validateObject(buildResult, WhenCreatingNew.class).validateAnnotations();
    // check if task is already completed
    // required workaround as we don't remove the BpmTasks immediately after the completion
    Optional<BuildTask> maybeBuildTask = buildCoordinator.getSubmittedBuildTask(buildId);
    if (maybeBuildTask.isPresent()) {
        BuildTask buildTask = maybeBuildTask.get();
        boolean temporaryBuild = buildTask.getBuildOptions().isTemporaryBuild();
        MDCUtils.addBuildContext(buildTask.getContentId(), temporaryBuild, ExpiresDate.getTemporaryBuildExpireDate(systemConfig.getTemporaryBuildsLifeSpan(), temporaryBuild), userService.currentUser().getId().toString());
        try {
            if (buildTask.getStatus().isCompleted()) {
                logger.warn("BuildTask with id: {} is already completed with status: {}", buildTask.getId(), buildTask.getStatus());
                return Response.status(Response.Status.GONE).entity("BuildTask with id: " + buildTask.getId() + " is already completed with status: " + buildTask.getStatus() + ".").build();
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Received build result wit full log: {}.", buildResult.toFullLogString());
            }
            logger.debug("Completing buildTask [{}] ...", buildId);
            buildCoordinator.completeBuild(buildTask, mapper.toEntity(buildResult));
            logger.debug("Completed buildTask [{}].", buildId);
            return Response.ok().build();
        } finally {
            MDCUtils.removeBuildContext();
        }
    } else {
        return Response.status(Response.Status.NOT_FOUND).entity("No active build with id: " + buildId).build();
    }
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) WhenCreatingNew(org.jboss.pnc.dto.validation.groups.WhenCreatingNew)

Example 32 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class BuildProviderImplTest method dependencyGraphTest.

@Test
public void dependencyGraphTest() {
    // given
    BuildTask bt100002 = mock(BuildTask.class);
    when(bt100002.getId()).thenReturn("100002");
    BuildTask bt110000 = mock(BuildTask.class);
    when(bt110000.getId()).thenReturn("110000");
    when(bt110000.getDependencies()).thenReturn(Collections.emptySet());
    when(bt110000.getDependants()).thenReturn(Collections.singleton(bt100002));
    runningBuilds.add(bt110000);
    mockBuildRecord(new Base32LongID(100000L), new Long[] { 100002L }, new Long[] {});
    mockBuildRecord(new Base32LongID(100001L), new Long[] { 100002L }, new Long[] {});
    BuildRecord currentBuild = mockBuildRecord(new Base32LongID(100002L), new Long[] { 100003L, 100005L, 100006L }, new Long[] { 100000L, 100001L, Long.valueOf(bt110000.getId()) });
    BuildRecord buildRecord100003 = mockBuildRecord(new Base32LongID(100003L), new Long[] { 100004L }, new Long[] { 100002L });
    mockBuildRecord(new Base32LongID(100004L), new Long[] {}, new Long[] { 100003L });
    mockBuildRecord(new Base32LongID(100005L), new Long[] {}, new Long[] { 100002L });
    mockBuildRecord(new Base32LongID(100006L), new Long[] {}, new Long[] { 100002L });
    // when
    Graph<Build> dependencyGraph = provider.getDependencyGraph(bt100002.getId());
    // then
    logger.info("Graph: {}", dependencyGraph.toString());
    assertEquals(8, dependencyGraph.getVertices().size());
    Vertex<Build> vertex = getBuildVertexByName(dependencyGraph, BuildMapper.idMapper.toDto(currentBuild.getId()));
    Build build = vertex.getData();
    assertEquals(BuildMapper.idMapper.toDto(currentBuild.getId()), build.getId());
    assertEquals(4, getOutgoingEdges(dependencyGraph, vertex).count());
    assertEquals(3, getIncommingEdges(dependencyGraph, vertex).count());
    Vertex<Build> vertex3 = getBuildVertexByName(dependencyGraph, BuildMapper.idMapper.toDto(buildRecord100003.getId()));
    assertEquals(1, getOutgoingEdges(dependencyGraph, vertex3).count());
    assertEquals(1, getIncommingEdges(dependencyGraph, vertex3).count());
    // then from running build
    Graph<Build> dependencyGraphFromRunning = provider.getDependencyGraph(bt110000.getId());
    Vertex<Build> runningVertex = getBuildVertexByName(dependencyGraphFromRunning, bt110000.getId());
    assertEquals(1, getOutgoingEdges(dependencyGraphFromRunning, runningVertex).count());
    assertEquals(1, getIncommingEdges(dependencyGraphFromRunning, runningVertex).count());
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 33 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class BuildProviderImplTest method mockBuildTaskWithSet.

private BuildTask mockBuildTaskWithSet(BuildSetTask buildSetTask) {
    BuildTask task = mockBuildTask();
    when(task.getBuildSetTask()).thenReturn(buildSetTask);
    when(task.getUser()).thenReturn(mock(User.class));
    return task;
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) User(org.jboss.pnc.model.User)

Example 34 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class BuildProviderImplTest method testFailFilterLikeRunningBuildsByBuildConfigName.

@Test
public void testFailFilterLikeRunningBuildsByBuildConfigName() {
    // Given
    mockBuildRecord();
    mockBuildTask();
    String givenBcName = "VeryLongAndComplicatedBcName";
    String givenBcNamePattern = "LongAndComplicated*";
    BuildTask givenBT = mockBuildTask(givenBcName);
    // When
    BuildPageInfo pageInfo = new BuildPageInfo(0, 2, "", "", false, true, givenBcNamePattern);
    Page<Build> builds = provider.getBuilds(pageInfo);
    // Then
    assertEquals(0, builds.getTotalHits());
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) Test(org.junit.Test)

Example 35 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class BuildProviderImplTest method shouldGetGraphWithDependencies.

@Test
public void shouldGetGraphWithDependencies() {
    // With
    Integer buildSetTaskId = 1;
    BuildSetTask buildSetTask = mock(BuildSetTask.class);
    when(buildSetTask.getId()).thenReturn(buildSetTaskId);
    BuildTask task = mockBuildTaskWithSet(buildSetTask);
    BuildTask taskDep = mockBuildTaskWithSet(buildSetTask);
    BuildTask taskDepDep = mockBuildTaskWithSet(buildSetTask);
    when(task.getDependencies()).thenReturn(asSet(taskDep));
    when(taskDep.getDependencies()).thenReturn(asSet(taskDepDep));
    // When
    Graph<Build> graph = provider.getBuildGraphForGroupBuild(Integer.toString(buildSetTaskId));
    // Then
    assertThat(graph.getVertices()).hasSize(3);
    List<String> buildTaskIDsOrderedByBCName = Stream.of(task, taskDep, taskDepDep).sorted(Comparator.comparing(t -> t.getBuildConfigurationAudited().getName())).map(t -> t.getId()).collect(Collectors.toList());
    assertThat(graph.getVertices().values().stream().map(Vertex::getName)).containsExactlyElementsOf(buildTaskIDsOrderedByBCName);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) Repository(org.jboss.pnc.spi.datastore.repositories.api.Repository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) BuildConfigSetRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigSetRecordRepository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) UserService(org.jboss.pnc.facade.util.UserService) Graph(org.jboss.pnc.dto.response.Graph) Assert.fail(org.junit.Assert.fail) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) User(org.jboss.pnc.model.User) SortInfoProducer(org.jboss.pnc.spi.datastore.repositories.SortInfoProducer) ResultStatus(org.jboss.pnc.enums.ResultStatus) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Result(org.jboss.pnc.spi.coordinator.Result) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) WireMock.matchingJsonPath(com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath) Base32LongID(org.jboss.pnc.model.Base32LongID) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) HashSet(java.util.HashSet) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Edge(org.jboss.pnc.dto.response.Edge) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) CorruptedDataException(org.jboss.pnc.facade.validation.CorruptedDataException) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) Logger(org.slf4j.Logger) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) Test(org.junit.Test) BuildRecord(org.jboss.pnc.model.BuildRecord) Mockito.when(org.mockito.Mockito.when) TemporaryBuildsCleanerAsyncInvoker(org.jboss.pnc.coordinator.maintenance.TemporaryBuildsCleanerAsyncInvoker) Page(org.jboss.pnc.dto.response.Page) Vertex(org.jboss.pnc.dto.response.Vertex) Consumer(java.util.function.Consumer) Build(org.jboss.pnc.dto.Build) Condition(org.assertj.core.api.Condition) RandomUtils.randInt(org.jboss.pnc.common.util.RandomUtils.randInt) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Vertex(org.jboss.pnc.dto.response.Vertex) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Build(org.jboss.pnc.dto.Build) Test(org.junit.Test)

Aggregations

BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)43 Test (org.junit.Test)23 BuildRecord (org.jboss.pnc.model.BuildRecord)15 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)15 Build (org.jboss.pnc.dto.Build)13 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)13 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)12 BuildOptions (org.jboss.pnc.spi.BuildOptions)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Inject (javax.inject.Inject)11 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)11 CoreException (org.jboss.pnc.spi.exception.CoreException)11 User (org.jboss.pnc.model.User)10 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)10 Date (java.util.Date)9 Set (java.util.Set)9 HashSet (java.util.HashSet)8 List (java.util.List)8