use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class VerifyManualDeletionOfBuildRepoTest method manuallyPromoteBuildRepoToChainGroup.
@Test
public void manuallyPromoteBuildRepoToChainGroup() throws Exception {
String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
String content = "This is a test " + System.currentTimeMillis();
String buildId = "build";
// create a dummy non-chained build execution and a repo session based on it
BuildExecution execution = new TestBuildExecution(buildId);
RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
String pkgType = MAVEN_PKG_KEY;
// simulate a build deploying a file.
StoreKey hostedKey = new StoreKey(pkgType, StoreType.hosted, buildId);
indy.module(IndyFoloContentClientModule.class).store(buildId, hostedKey, path, new ByteArrayInputStream(content.getBytes()));
// now, extract the build artifacts. This will trigger promotion of the build hosted repo to the chain group.
RepositoryManagerResult result = session.extractBuildArtifacts(true);
// do some sanity checks while we're here
List<Artifact> deps = result.getBuiltArtifacts();
assertThat(deps.size(), equalTo(1));
Artifact a = deps.get(0);
assertThat(a.getFilename(), equalTo(new File(path).getName()));
// construct a dummy BuildRecord for use below
BuildRecord record = new BuildRecord();
record.setBuildContentId(buildId);
// unset the readonly flag on the hosted repo to allow its deletion
IndyStoresClientModule indyStoreAdmin = indy.stores();
StoreKey key = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, record.getBuildContentId());
HostedRepository store = indyStoreAdmin.load(key, HostedRepository.class);
store.setReadonly(false);
indyStoreAdmin.update(store, "Unsetting readonly-flag to allow deletion");
// manually delete the build to the public group (since it's convenient)
RunningRepositoryDeletion deletion = driver.deleteBuild(record, pkgType, accessToken);
deletion.monitor(completed -> assertThat("Manual deletion failed.", completed.isSuccessful(), equalTo(true)), error -> {
error.printStackTrace();
fail("Failed to manually delete: " + error.getMessage());
});
// end result: the build hosted repo should no longer exist.
assertThat(indyStoreAdmin.exists(hostedKey), equalTo(false));
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class VerifyManualPromotionOfBuildRepoTest method manuallyPromoteBuildRepoToChainGroup.
@Test
public void manuallyPromoteBuildRepoToChainGroup() throws Exception {
String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
String content = "This is a test " + System.currentTimeMillis();
// String chainId = "chain";
String buildId = "build";
// create a dummy non-chained build execution and a repo session based on it
BuildExecution execution = new TestBuildExecution(buildId);
RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
String pkgType = MAVEN_PKG_KEY;
// simulate a build deploying a file.
StoreKey hostedKey = new StoreKey(pkgType, StoreType.hosted, buildId);
indy.module(IndyFoloContentClientModule.class).store(buildId, hostedKey, path, new ByteArrayInputStream(content.getBytes()));
// now, extract the build artifacts. This will trigger promotion of the build hosted repo to the chain group.
RepositoryManagerResult result = session.extractBuildArtifacts(true);
// do some sanity checks while we're here
List<Artifact> deps = result.getBuiltArtifacts();
assertThat(deps.size(), equalTo(1));
Artifact a = deps.get(0);
assertThat(a.getFilename(), equalTo(new File(path).getName()));
// construct a dummy BuildRecord for use below
BuildRecord record = new BuildRecord();
record.setBuildContentId(buildId);
// manually promote the build to the public group (since it's convenient)
RunningRepositoryPromotion promotion = driver.promoteBuild(record, pkgType, PUBLIC, accessToken);
promotion.monitor(completed -> assertThat("Manual promotion failed.", completed.isSuccessful(), equalTo(true)), error -> {
error.printStackTrace();
fail("Failed to manually promote: " + error.getMessage());
});
// end result: the chain group should contain the build hosted repo.
StoreKey publicKey = new StoreKey(pkgType, StoreType.group, PUBLIC);
Group publicGroup = indy.stores().load(publicKey, Group.class);
System.out.println("public group constituents: " + publicGroup.getConstituents());
assertThat(publicGroup.getConstituents().contains(hostedKey), equalTo(true));
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class BuildProviderImpl method setBuiltArtifacts.
@RolesAllowed(SYSTEM_USER)
@Override
public void setBuiltArtifacts(String buildId, List<String> artifactIds) {
Set<Integer> ids = artifactIds.stream().map(Integer::valueOf).collect(Collectors.toSet());
List<Artifact> artifacts = artifactRepository.queryWithPredicates(withIds(ids));
if (ids.size() != artifacts.size()) {
artifacts.stream().map(Artifact::getId).forEach(ids::remove);
throw new InvalidEntityException("Artifacts not found, missing ids: " + ids);
}
final Base32LongID id = parseId(buildId);
BuildRecord buildRecord = repository.queryById(id);
for (Artifact artifact : artifacts) {
if (artifact.getBuildRecord() != null && !id.equals(artifact.getBuildRecord().getId())) {
throw new ConflictedEntryException("Artifact " + artifact.getId() + " is already marked as built by different build.", BuildRecord.class, BuildMapper.idMapper.toDto(artifact.getBuildRecord().getId()));
}
artifact.setBuildRecord(buildRecord);
}
HashSet<Artifact> oldBuiltArtifacts = new HashSet<>(buildRecord.getBuiltArtifacts());
oldBuiltArtifacts.stream().filter(a -> !ids.contains(a.getId())).forEach(a -> a.setBuildRecord(null));
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class BrewPusherImpl method doPushBuild.
private BuildPushResult doPushBuild(Base32LongID buildId, BuildPushParameters buildPushParameters, Long buildPushResultId) throws ProcessException {
// TODO START timing event
userLog.info("Push started.");
// collect and validate input data
BuildRecord buildRecord = getLatestSuccessfullyExecutedBuildRecord(buildId);
if (buildRecord.getExecutionRootName() == null && !buildRecord.getBuildConfigurationAudited().getGenericParameters().containsKey(BREW_BUILD_NAME.name())) {
throw new InvalidEntityException("Build " + buildId + " cannot be pushed to brew, because it is missing " + Attributes.BUILD_BREW_NAME + " attribute with brew name.");
}
List<Artifact> artifacts = artifactRepository.queryWithPredicates(ArtifactPredicates.withBuildRecordId(buildRecord.getId()));
if (hasBadArtifactQuality(artifacts)) {
String message = "Build contains artifacts of insufficient quality: BLACKLISTED/DELETED.";
log.debug(message);
BuildPushResult pushResult = BuildPushResult.builder().buildId(BuildMapper.idMapper.toDto(buildId)).status(BuildPushStatus.REJECTED).id(buildPushResultId.toString()).logContext(buildPushResultId.toString()).message(message).build();
throw new OperationNotAllowedException(message, pushResult);
}
log.debug("Pushing Build.id {}.", buildRecord.getId());
BuildPushOperation buildPushOperation = new BuildPushOperation(buildRecord, buildPushResultId, buildPushParameters.getTagPrefix(), buildPushParameters.isReimport(), getCompleteCallbackUrlTemplate());
Result pushResult = buildResultPushManager.push(buildPushOperation, userService.currentUserToken());
log.info("Push Result {}.", pushResult);
BuildPushResult result = BuildPushResult.builder().id(pushResult.getId()).buildId(pushResult.getBuildId()).status(pushResult.getStatus()).logContext(pushResult.getId()).message(pushResult.getMessage()).build();
// verify operation status
switch(pushResult.getStatus()) {
case ACCEPTED:
userLog.info("Push ACCEPTED.");
return result;
case REJECTED:
userLog.warn("Push REJECTED.");
throw new AlreadyRunningException(pushResult.getMessage(), result);
case SYSTEM_ERROR:
userLog.error("Brew push failed: " + pushResult.getMessage());
throw new ProcessException(pushResult.getMessage());
default:
userLog.error("Invalid push result status.");
throw new ProcessException("Invalid push result status.");
}
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class ProjectBuilder method assertArtifactsPresent.
public static void assertArtifactsPresent(Set<Artifact> artifacts) {
assertTrue("Missing artifacts.", artifacts.size() > 0);
Artifact artifact = artifacts.iterator().next();
assertTrue("Invalid artifact in result.", artifact.getIdentifier().startsWith(ArtifactBuilder.IDENTIFIER_PREFIX));
}
Aggregations