use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class BuildExecutionTest method testBuild.
@Test
public void testBuild() throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException {
BuildConfiguration buildConfiguration = configurationBuilder.build(1, "c1-java");
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper);
List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesSuccess();
// check build statuses
checkBuildStatuses(statusChangedEvents, expectedStatuses);
// check results
BuildResult buildResult = buildExecutionResultWrapper.get();
// check results: logs
BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
String buildLog = buildDriverResult.getBuildLog();
Assert.assertTrue("Invalid build log.", buildLog.contains("Finished: SUCCESS"));
// check results: artifacts
RepositoryManagerResult repositoryManagerResult = buildResult.getRepositoryManagerResult().get();
Assert.assertTrue("Missing build artifacts.", repositoryManagerResult.getBuiltArtifacts().size() > 0);
Assert.assertTrue("Missing build dependencies.", repositoryManagerResult.getDependencies().size() > 0);
Artifact artifact = repositoryManagerResult.getBuiltArtifacts().iterator().next();
Assert.assertTrue("Invalid built artifact in the result.", artifact.getIdentifier().startsWith(ArtifactBuilder.IDENTIFIER_PREFIX));
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class BuildResultPushManager method createCausewayPushRequest.
private BuildImportRequest createCausewayPushRequest(BuildRecord buildRecord, String tagPrefix, URI callBackUrl, String authToken, Long pushResultId, boolean reimport) {
BuildEnvironment buildEnvironment = buildRecord.getBuildConfigurationAudited().getBuildEnvironment();
logger.debug("BuildRecord: {}", buildRecord.getId());
logger.debug("BuildEnvironment: {}", buildEnvironment);
BuildRoot buildRoot = BuildRoot.builder().container("DOCKER_IMAGE").containerArchitecture(// TODO set based on env, some env has native build tools
"x86_64").host("rhel").hostArchitecture("x86_64").tools(buildEnvironment.getAttributes()).build();
List<Artifact> builtArtifactEntities = artifactRepository.queryWithPredicates(ArtifactPredicates.withBuildRecordId(buildRecord.getId()));
List<Artifact> dependencyEntities = artifactRepository.queryWithPredicates(ArtifactPredicates.withDependantBuildRecordId(buildRecord.getId()));
logger.debug("Preparing BuildImportRequest containing {} built artifacts and {} dependencies.", builtArtifactEntities.size(), dependencyEntities.size());
BuildType buildType = buildRecord.getBuildConfigurationAudited().getBuildType();
Set<Dependency> dependencies = collectDependencies(dependencyEntities);
Set<BuiltArtifact> builtArtifacts = collectBuiltArtifacts(builtArtifactEntities, buildType);
Map<String, String> callbackHeaders = Collections.singletonMap(MDCUtils.getMDCToHeaderMappings().get(MDCKeys.PROCESS_CONTEXT_KEY), pushResultId.toString());
Request callbackTarget = Request.builder().method(Request.Method.POST).authTokenHeader(authToken).uri(callBackUrl).header(MDCUtils.getMDCToHeaderMappings().get(MDCKeys.PROCESS_CONTEXT_KEY), pushResultId.toString()).build();
String executionRootName = buildRecord.getExecutionRootName();
// prefer execution root name from generic parameters
BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(buildRecord.getBuildConfigurationAuditedIdRev());
Map<String, String> genericParameters = buildConfigurationAudited.getGenericParameters();
if (executionRootName == null) {
if (genericParameters.containsKey(BREW_BUILD_NAME.name())) {
executionRootName = genericParameters.get(BREW_BUILD_NAME.name());
} else {
throw new IllegalArgumentException("Provided build " + buildRecord.getId() + " is missing brew name. Please set build attribute " + BUILD_BREW_NAME + ".");
}
}
Build build = getBuild(buildRecord, tagPrefix, buildRoot, dependencies, builtArtifacts, executionRootName, buildType);
return new BuildImportRequest(callbackTarget, build, reimport);
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class TemporaryBuildsCleaner method removeBuiltArtifacts.
private void removeBuiltArtifacts(BuildRecord buildRecord) {
Set<Artifact> toDelete = new HashSet<>(buildRecord.getBuiltArtifacts());
for (Artifact artifact : toDelete) {
log.debug(String.format("Deleting relation BR-Artifact. BR=%s, artifact=%s", buildRecord, artifact.getDescriptiveString()));
if (!artifact.getDeliveredInProductMilestones().isEmpty()) {
log.error("Temporary artifact was delivered in milestone! Artifact: " + artifact + "\n Milestones: " + artifact.getDeliveredInProductMilestones());
continue;
}
artifact.setBuildRecord(null);
deleteArtifact(artifact);
}
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class DefaultDatastore method fetchOrSaveRequiredTargetRepositories.
private void fetchOrSaveRequiredTargetRepositories(Collection<Artifact> artifacts, Map<TargetRepository.IdentifierPath, TargetRepository> storedTargetRepositories) {
Map<TargetRepository.IdentifierPath, TargetRepository> requiredTargetRepositories = new HashMap<>();
for (Artifact artifact : artifacts) {
TargetRepository targetRepository = artifact.getTargetRepository();
logger.trace("Adding repository for artifact: {}.", artifact.toString());
if (!storedTargetRepositories.containsKey(targetRepository.getIdentifierPath())) {
requiredTargetRepositories.put(targetRepository.getIdentifierPath(), targetRepository);
}
}
if (requiredTargetRepositories.size() > 0) {
List<TargetRepository> targetRepositoriesInDB = targetRepositoryRepository.queryByIdentifiersAndPaths(requiredTargetRepositories.keySet());
for (TargetRepository targetRepository : targetRepositoriesInDB) {
storedTargetRepositories.put(targetRepository.getIdentifierPath(), targetRepository);
requiredTargetRepositories.remove(targetRepository.getIdentifierPath());
}
for (TargetRepository targetRepository : requiredTargetRepositories.values()) {
// NCL-5474: This can potentionally cause unique constraint violation if two builds finish at the same
// time, both with the same new target repository. This is unlikely to happen, so we take the risk.
TargetRepository savedTargetRepository = targetRepositoryRepository.save(targetRepository);
storedTargetRepositories.put(targetRepository.getIdentifierPath(), savedTargetRepository);
}
}
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class DefaultDatastore method checkForBuiltArtifacts.
@Override
public Map<Artifact, String> checkForBuiltArtifacts(Collection<Artifact> artifacts) {
Map<RepositoryType, Map<String, Artifact>> repoTypes = new HashMap<>();
for (Artifact artifact : artifacts) {
RepositoryType repoType = artifact.getTargetRepository().getRepositoryType();
if (!repoTypes.containsKey(repoType)) {
repoTypes.put(repoType, new HashMap<>());
}
Map<String, Artifact> identifiers = repoTypes.get(repoType);
identifiers.put(artifact.getIdentifier(), artifact);
}
Map<Artifact, String> conflicts = new HashMap<>();
for (RepositoryType repoType : repoTypes.keySet()) {
Map<String, Artifact> identifiers = repoTypes.get(repoType);
List<Artifact> conflicting = artifactRepository.queryWithPredicates(withIdentifierInAndBuilt(identifiers.keySet()));
for (Artifact conflict : conflicting) {
if (conflict.getTargetRepository().getRepositoryType() == repoType) {
Artifact artifact = identifiers.get(conflict.getIdentifier());
conflicts.put(artifact, ARTIFACT_ALREADY_BUILT_CONFLICT_MESSAGE + conflict.getBuildRecord().getId());
}
}
}
return conflicts;
}
Aggregations