use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.
the class IndyRepositorySession method extractBuildArtifacts.
/**
* Retrieve tracking report from repository manager. Add each tracked download to the dependencies of the build
* result. Add each tracked upload to the built artifacts of the build result. Promote uploaded artifacts to the
* product-level storage. Finally delete the group associated with the completed build.
*
* @param liveBuild {@inheritDoc} - if true, the promotion of the collected artifacts and dependencies is done,
* tracking report is sealed and the build group is removed, if false it only reads the data without any
* actions
*/
@Override
public RepositoryManagerResult extractBuildArtifacts(final boolean liveBuild) throws RepositoryManagerException {
TrackedContentDTO report = sealAndGetTrackingReport(liveBuild);
Comparator<Artifact> comp = (one, two) -> one.getIdentifier().compareTo(two.getIdentifier());
Uploads uploads = collectUploads(report);
List<Artifact> uploadedArtifacts = uploads.getData();
Collections.sort(uploadedArtifacts, comp);
List<Artifact> downloadedArtifacts = null;
String log = "";
CompletionStatus status = CompletionStatus.SUCCESS;
try {
downloadedArtifacts = processDownloads(report, liveBuild);
Collections.sort(downloadedArtifacts, comp);
} catch (PromotionValidationException ex) {
status = CompletionStatus.FAILED;
log = ex.getMessage();
logger.warn("Dependencies promotion failed. Error(s): {}", log);
userLog.error("Dependencies promotion failed. Error(s): {}", log);
}
if (liveBuild) {
deleteBuildGroup();
}
// if the promotion of dependencies succeeded...
if (status == CompletionStatus.SUCCESS) {
logger.info("Returning built artifacts / dependencies:\nUploads:\n {}\n\nDownloads:\n {}\n\n", StringUtils.join(uploads.getData(), "\n "), StringUtils.join(downloadedArtifacts, "\n "));
if (liveBuild) {
logger.info("BEGIN: promotion to build content set");
StopWatch stopWatch = StopWatch.createStarted();
try {
promoteToBuildContentSet(uploads.getPromotion());
} catch (PromotionValidationException ex) {
status = CompletionStatus.FAILED;
log = ex.getMessage();
logger.warn("Built artifact promotion failed. Error(s): {}", log);
userLog.error("Built artifact promotion failed. Error(s): {}", log);
}
logger.info("END: promotion to build content set, took: {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
stopWatch.reset();
}
}
if (status == CompletionStatus.FAILED) {
// prevent saving artifacts and dependencies to a failed build
downloadedArtifacts = Collections.emptyList();
uploadedArtifacts = Collections.emptyList();
}
return new IndyRepositoryManagerResult(uploadedArtifacts, downloadedArtifacts, buildContentId, log, status);
}
use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.
the class IndyRunningPromotion method monitor.
/**
* Trigger the repository promotion configured for this instance, and send the result to the appropriate consumer.
*
* @param onComplete The consumer which will handle non-error results
* @param onError Handles errors
*/
@Override
public void monitor(Consumer<CompletedRepositoryPromotion> onComplete, Consumer<Exception> onError) {
try {
StoreKey fromKey = new StoreKey(pakageType, fromType, fromId);
if (!indy.stores().exists(fromKey)) {
throw new RepositoryManagerException("No such %s repository: %s", fromType.singularEndpointName(), fromId);
}
StoreKey toKey = new StoreKey(pakageType, StoreType.group, toId);
Group recordSetGroup = indy.stores().load(toKey, Group.class);
if (recordSetGroup == null) {
throw new RepositoryManagerException("No such group: %s", toId);
}
recordSetGroup.addConstituent(fromKey);
boolean result = indy.stores().update(recordSetGroup, "Promoting " + fromType.singularEndpointName() + " repository : " + fromId + " to group: " + toId);
onComplete.accept(new IndyCompletedPromotion(result));
} catch (IndyClientException | RepositoryManagerException e) {
onError.accept(e);
}
}
use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.
the class DefaultBuildExecutor method cancel.
@Override
public void cancel(String executionConfigurationId) throws ExecutorException {
DefaultBuildExecutionSession buildExecutionSession = runningExecutions.get(executionConfigurationId);
if (buildExecutionSession != null) {
log.info("Cancelling build {}.", buildExecutionSession.getId());
if (buildExecutionSession.cancel()) {
String buildContentId = buildExecutionSession.getBuildExecutionConfiguration().getBuildContentId();
RunningEnvironment runningEnvironment = buildExecutionSession.getRunningEnvironment();
if (runningEnvironment == null) {
log.warn("Could not retrieve running environment for build {}", buildContentId);
} else {
RepositorySession repositorySession = runningEnvironment.getRepositorySession();
if (repositorySession == null) {
log.warn("Could not retrieve repository session for build {}", buildContentId);
} else {
try {
repositorySession.deleteBuildGroup();
} catch (RepositoryManagerException e) {
log.error("Error deleting build group for build " + buildContentId + " when canceling it.", e);
}
}
}
}
} else {
log.warn("Trying to cancel non existing session.");
}
}
use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.
the class BuildMaintenanceEndpointImpl method collectRepoManagerResult.
@Override
public Response collectRepoManagerResult(String id) {
logger.info("Getting repository manager result for build record id {}.", id);
RepositoryManagerResult result;
try {
result = repositoryManager.collectRepoManagerResult(id);
} catch (RepositoryManagerException ex) {
logger.error("Error when collecting repository manager result for build record " + id, ex);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.toString()).build();
}
if (result == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
return Response.ok(result).build();
}
use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.
the class ExtraDependencyRepositoriesTest method shouldAddExtraRepositoryToBuildGroup.
@Test
public void shouldAddExtraRepositoryToBuildGroup() throws RepositoryManagerException, IndyClientException {
final String REPO_NAME = "i-test-com";
Map<String, String> genericParams = createGenericParamsMap("http://test.com/maven/");
BuildExecution execution = new TestBuildExecution();
RepositorySession repositorySession = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, genericParams, false);
assertNotNull(repositorySession);
StoreKey buildGroupKey = new StoreKey(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, StoreType.group, repositorySession.getBuildRepositoryId());
Group buildGroup = indy.stores().load(buildGroupKey, Group.class);
long hits = buildGroup.getConstituents().stream().filter((key) -> REPO_NAME.equals(key.getName())).count();
assertEquals(1, hits);
}
Aggregations