Search in sources :

Example 1 with LaunchBuilder

use of com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder in project service-api by reportportal.

the class StartLaunchHandlerImpl method startLaunch.

@Override
@Transactional
public StartLaunchRS startLaunch(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartLaunchRQ request) {
    validateRoles(projectDetails, request);
    final Launch savedLaunch = Optional.of(request.isRerun()).filter(Boolean::booleanValue).map(rerun -> rerunHandler.handleLaunch(request, projectDetails.getProjectId(), user)).orElseGet(() -> {
        Launch launch = new LaunchBuilder().addStartRQ(request).addAttributes(request.getAttributes()).addProject(projectDetails.getProjectId()).addUserId(user.getUserId()).get();
        launchRepository.save(launch);
        launchRepository.refresh(launch);
        return launch;
    });
    eventPublisher.publishEvent(new StartLaunchEvent(savedLaunch.getId()));
    messageBus.publishActivity(new LaunchStartedEvent(TO_ACTIVITY_RESOURCE.apply(savedLaunch), user.getUserId(), user.getUsername()));
    StartLaunchRS response = new StartLaunchRS();
    response.setId(savedLaunch.getUuid());
    response.setNumber(savedLaunch.getNumber());
    return response;
}
Also used : Primary(org.springframework.context.annotation.Primary) Launch(com.epam.ta.reportportal.entity.launch.Launch) Autowired(org.springframework.beans.factory.annotation.Autowired) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StartLaunchEvent(com.epam.reportportal.extension.event.StartLaunchEvent) RerunHandler(com.epam.ta.reportportal.core.launch.rerun.RerunHandler) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) LaunchStartedEvent(com.epam.ta.reportportal.core.events.activity.LaunchStartedEvent) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) Service(org.springframework.stereotype.Service) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.LaunchConverter.TO_ACTIVITY_RESOURCE) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Optional(java.util.Optional) StartLaunchHandler(com.epam.ta.reportportal.core.launch.StartLaunchHandler) Transactional(org.springframework.transaction.annotation.Transactional) LaunchStartedEvent(com.epam.ta.reportportal.core.events.activity.LaunchStartedEvent) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) StartLaunchEvent(com.epam.reportportal.extension.event.StartLaunchEvent) Launch(com.epam.ta.reportportal.entity.launch.Launch) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LaunchBuilder

use of com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder in project service-api by reportportal.

the class StopLaunchHandlerImpl method stopLaunch.

@Override
public OperationCompletionRS stopLaunch(Long launchId, FinishExecutionRQ finishLaunchRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    Launch launch = launchRepository.findById(launchId).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, launchId));
    validateRoles(launch, user, projectDetails);
    validate(launch, finishLaunchRQ);
    launch = new LaunchBuilder(launch).addDescription(ofNullable(finishLaunchRQ.getDescription()).orElse(ofNullable(launch.getDescription()).orElse("")).concat(LAUNCH_STOP_DESCRIPTION)).addStatus(ofNullable(finishLaunchRQ.getStatus()).orElse(STOPPED.name())).addEndTime(ofNullable(finishLaunchRQ.getEndTime()).orElse(new Date())).addAttributes(finishLaunchRQ.getAttributes()).addAttribute(new ItemAttributeResource("status", "stopped")).get();
    launchRepository.save(launch);
    testItemRepository.interruptInProgressItems(launch.getId());
    messageBus.publishActivity(new LaunchFinishForcedEvent(TO_ACTIVITY_RESOURCE.apply(launch), user.getUserId(), user.getUsername()));
    eventPublisher.publishEvent(new LaunchFinishedEvent(TO_ACTIVITY_RESOURCE.apply(launch), user.getUserId(), user.getUsername()));
    return new OperationCompletionRS("Launch with ID = '" + launchId + "' successfully stopped.");
}
Also used : ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) LaunchFinishForcedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishForcedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) Launch(com.epam.ta.reportportal.entity.launch.Launch) Date(java.util.Date) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 3 with LaunchBuilder

use of com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder in project service-api by reportportal.

the class UpdateLaunchHandlerImpl method updateLaunch.

@Override
public OperationCompletionRS updateLaunch(Long launchId, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user, UpdateLaunchRQ rq) {
    Project project = getProjectHandler.getProject(projectDetails);
    Launch launch = launchRepository.findById(launchId).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, launchId.toString()));
    validate(launch, user, projectDetails, rq.getMode());
    LaunchModeEnum previousMode = launch.getMode();
    launch = new LaunchBuilder(launch).addMode(rq.getMode()).addDescription(rq.getDescription()).overwriteAttributes(rq.getAttributes()).get();
    launchRepository.save(launch);
    if (!previousMode.equals(launch.getMode())) {
        reindexLogs(launch, AnalyzerUtils.getAnalyzerConfig(project), project.getId());
    }
    return new OperationCompletionRS("Launch with ID = '" + launch.getId() + "' successfully updated.");
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Launch(com.epam.ta.reportportal.entity.launch.Launch) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 4 with LaunchBuilder

use of com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder in project service-api by reportportal.

the class DemoDataLaunchService method startLaunch.

@Transactional
public Launch startLaunch(String name, User user, ReportPortalUser.ProjectDetails projectDetails) {
    StartLaunchRQ rq = new StartLaunchRQ();
    rq.setMode(Mode.DEFAULT);
    rq.setDescription(ContentUtils.getLaunchDescription());
    LocalDateTime now = LocalDateTime.now();
    rq.setName(name);
    rq.setStartTime(Date.from(now.atZone(ZoneId.systemDefault()).toInstant()));
    rq.setUuid(UUID.randomUUID().toString());
    Set<ItemAttributesRQ> attributes = Sets.newHashSet(new ItemAttributesRQ("platform", platformValues[new Random().nextInt(platformValues.length)]), new ItemAttributesRQ(null, "demo"), new ItemAttributesRQ("build", "3." + now.getDayOfMonth() + "." + now.getHour() + "." + now.getMinute() + "." + now.getSecond()));
    Launch launch = new LaunchBuilder().addStartRQ(rq).addAttributes(attributes).addProject(projectDetails.getProjectId()).get();
    launch.setUserId(user.getId());
    launchRepository.save(launch);
    launchRepository.refresh(launch);
    return launch;
}
Also used : LocalDateTime(java.time.LocalDateTime) Random(java.util.Random) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) Launch(com.epam.ta.reportportal.entity.launch.Launch) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with LaunchBuilder

use of com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder in project service-api by reportportal.

the class AbstractLaunchMergeStrategy method createResultedLaunch.

/**
 * Create launch that will be the result of merge
 *
 * @param projectId       {@link Project#getId()}
 * @param userId          {@link ReportPortalUser#getUserId()}
 * @param mergeLaunchesRQ {@link MergeLaunchesRQ}
 * @param launches        {@link List} of the {@link Launch}
 * @return launch
 */
private Launch createResultedLaunch(Long projectId, Long userId, MergeLaunchesRQ mergeLaunchesRQ, List<Launch> launches) {
    Date startTime = ofNullable(mergeLaunchesRQ.getStartTime()).orElse(EntityUtils.TO_DATE.apply(launches.stream().min(Comparator.comparing(Launch::getStartTime)).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Invalid launches")).getStartTime()));
    Date endTime = ofNullable(mergeLaunchesRQ.getEndTime()).orElse(EntityUtils.TO_DATE.apply(launches.stream().max(Comparator.comparing(Launch::getEndTime)).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Invalid launches")).getEndTime()));
    expect(endTime, time -> !time.before(startTime)).verify(FINISH_TIME_EARLIER_THAN_START_TIME, TO_LOCAL_DATE_TIME.apply(endTime), startTime, projectId);
    StartLaunchRQ startRQ = new StartLaunchRQ();
    startRQ.setMode(ofNullable(mergeLaunchesRQ.getMode()).orElse(Mode.DEFAULT));
    startRQ.setDescription(ofNullable(mergeLaunchesRQ.getDescription()).orElse(launches.stream().map(Launch::getDescription).collect(joining("\n\n"))));
    startRQ.setName(ofNullable(mergeLaunchesRQ.getName()).orElse("Merged: " + launches.stream().map(Launch::getName).distinct().collect(joining(", "))));
    startRQ.setStartTime(startTime);
    Launch launch = new LaunchBuilder().addStartRQ(startRQ).addProject(projectId).addStatus(IN_PROGRESS.name()).addUserId(userId).addEndTime(endTime).get();
    launch.setHasRetries(launches.stream().anyMatch(Launch::isHasRetries));
    launchRepository.save(launch);
    launchRepository.refresh(launch);
    mergeAttributes(mergeLaunchesRQ.getAttributes(), launches, launch);
    return launch;
}
Also used : TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) java.util(java.util) TestItemUniqueIdGenerator(com.epam.ta.reportportal.core.item.identity.TestItemUniqueIdGenerator) Project(com.epam.ta.reportportal.entity.project.Project) TestItem(com.epam.ta.reportportal.entity.item.TestItem) TO_LOCAL_DATE_TIME(com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) Supplier(java.util.function.Supplier) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) EntityUtils(com.epam.ta.reportportal.commons.EntityUtils) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) LogRepository(com.epam.ta.reportportal.dao.LogRepository) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) MergeLaunchesRQ(com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ) Launch(com.epam.ta.reportportal.entity.launch.Launch) AttachmentRepository(com.epam.ta.reportportal.dao.AttachmentRepository) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) Optional.ofNullable(java.util.Optional.ofNullable) IdentityUtil(com.epam.ta.reportportal.core.item.identity.IdentityUtil) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Collectors.joining(java.util.stream.Collectors.joining) Collectors.toList(java.util.stream.Collectors.toList) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) FINISH_TIME_EARLIER_THAN_START_TIME(com.epam.ta.reportportal.ws.model.ErrorType.FINISH_TIME_EARLIER_THAN_START_TIME) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) FROM_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.ItemAttributeConverter.FROM_RESOURCE) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) Mode(com.epam.ta.reportportal.ws.model.launch.Mode) IN_PROGRESS(com.epam.ta.reportportal.entity.enums.StatusEnum.IN_PROGRESS) LaunchMergeStrategy(com.epam.ta.reportportal.core.item.merge.LaunchMergeStrategy) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) Launch(com.epam.ta.reportportal.entity.launch.Launch) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)

Aggregations

Launch (com.epam.ta.reportportal.entity.launch.Launch)7 LaunchBuilder (com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)5 StartLaunchRQ (com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 LaunchFinishedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent)2 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 Project (com.epam.ta.reportportal.entity.project.Project)2 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)2 ItemAttributeResource (com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource)2 StartLaunchEvent (com.epam.reportportal.extension.event.StartLaunchEvent)1 EntityUtils (com.epam.ta.reportportal.commons.EntityUtils)1 TO_LOCAL_DATE_TIME (com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME)1 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)1 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 LaunchFinishForcedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishForcedEvent)1 LaunchStartedEvent (com.epam.ta.reportportal.core.events.activity.LaunchStartedEvent)1