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;
}
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.");
}
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.");
}
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;
}
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;
}
Aggregations