use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.
the class DefaultBuildExecutor method configureRepository.
private RepositorySession configureRepository(DefaultBuildExecutionSession buildExecutionSession) {
if (buildExecutionSession.isCanceled()) {
return null;
}
ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Setting up repository...");
buildExecutionSession.setStatus(BuildExecutionStatus.REPO_SETTING_UP);
BuildType buildType = buildExecutionSession.getBuildExecutionConfiguration().getBuildType();
if (buildType == null) {
throw new BuildProcessException("Missing required value buildExecutionConfiguration.buildType");
}
RepositoryType repositoryType = BuildTypeToRepositoryType.getRepositoryType(buildType);
try {
RepositoryManager repositoryManager = repositoryManagerFactory.getRepositoryManager(repositoryType);
BuildExecution buildExecution = buildExecutionSession.getBuildExecutionConfiguration();
String serviceAccountToken = (serviceClient == null ? null : serviceClient.getAuthToken());
RepositorySession buildRepository = repositoryManager.createBuildRepositoryWithRetries(buildExecution, buildExecutionSession.getAccessToken(), serviceAccountToken, repositoryType, buildExecutionSession.getBuildExecutionConfiguration().getGenericParameters(), buildExecutionSession.getBuildExecutionConfiguration().isBrewPullActive());
return buildRepository;
} catch (Throwable e) {
throw new BuildProcessException(e);
} finally {
ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Repository setup complete.");
}
}
use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.
the class DefaultBuildExecutor method completeExecution.
private Void completeExecution(DefaultBuildExecutionSession buildExecutionSession, Throwable e) {
String buildExecutionId = buildExecutionSession.getId();
try {
// Ends when the result is stored by the Orchestrator
ProcessStageUtils.logProcessStageBegin("FINALIZING_BUILD", "Finalizing build ...");
if (e != null) {
log.debug("Finalizing FAILED execution. Exception: ", e);
} else {
log.debug("Finalizing SUCCESS execution.");
}
buildExecutionSession.setStatus(BuildExecutionStatus.FINALIZING_EXECUTION);
if (buildExecutionSession.getStartTime() == null) {
buildExecutionSession.setException(new ExecutorException("Missing start time."));
}
if (e != null) {
stopRunningEnvironment(e);
} else {
try {
destroyEnvironment(buildExecutionSession);
} catch (BuildProcessException destroyException) {
e = destroyException;
}
}
if (e != null) {
buildExecutionSession.setException(new ExecutorException(e));
}
if (buildExecutionSession.getEndTime() != null) {
buildExecutionSession.setException(new ExecutorException("End time already set."));
} else {
buildExecutionSession.setEndTime(new Date());
}
// check if any of previous statuses indicated "failed" state
if (buildExecutionSession.isCanceled()) {
buildExecutionSession.setStatus(BuildExecutionStatus.CANCELLED);
userLog.info("Build execution completed (canceled).");
} else if (buildExecutionSession.hasFailed()) {
buildExecutionSession.setStatus(BuildExecutionStatus.DONE_WITH_ERRORS);
userLog.warn("Build execution completed with errors.");
} else {
buildExecutionSession.setStatus(BuildExecutionStatus.DONE);
userLog.info("Build execution completed successfully.");
}
log.debug("Removing buildExecutionTask [" + buildExecutionId + "] from list of running tasks.");
runningExecutions.remove(buildExecutionId);
userLog.info("Build execution completed.");
} catch (Throwable t) {
userLog.error("Unable to complete execution!", t);
String executorException = "Unable to recover, see system log for the details.";
if (t.getMessage() != null) {
executorException += " " + t.getMessage();
}
buildExecutionSession.setException(new ExecutorException(executorException));
buildExecutionSession.setEndTime(new Date());
buildExecutionSession.setStatus(BuildExecutionStatus.SYSTEM_ERROR);
runningExecutions.remove(buildExecutionId);
} finally {
RunningEnvironment runningEnvironment = buildExecutionSession.getRunningEnvironment();
if (runningEnvironment == null) {
log.warn("Could not close Maven repository session [" + buildExecutionId + "]. Running environment was not set!");
} else {
RepositorySession repositorySession = runningEnvironment.getRepositorySession();
if (repositorySession == null) {
log.warn("Could not close Maven repository session [" + buildExecutionId + "]. Repository session was not set!");
} else {
log.debug("Closing Maven repository session [" + buildExecutionId + "].");
repositorySession.close();
}
}
}
return null;
}
use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.
the class OpenshiftStartedEnvironment method monitorInitialization.
/**
* retries is decremented in retryPod in case of pod failing to start
*
* @param onComplete
* @param onError
* @param retries
*/
private void monitorInitialization(Consumer<RunningEnvironment> onComplete, Consumer<Exception> onError, int retries) {
cancelHook = () -> onComplete.accept(null);
CompletableFuture<Void> podFuture = creatingPod.thenComposeAsync(nul -> {
CancellableCompletableFuture<Void> monitor = pollingMonitor.monitor(this::isPodRunning, pollingMonitorCheckInterval, pollingMonitorTimeout, TimeUnit.SECONDS);
addFuture(monitor);
return monitor;
}, executor);
CompletableFuture<Void> serviceFuture = creatingService.thenComposeAsync(nul -> {
CancellableCompletableFuture<Void> monitor = pollingMonitor.monitor(this::isServiceRunning, pollingMonitorCheckInterval, pollingMonitorTimeout, TimeUnit.SECONDS);
addFuture(monitor);
return monitor;
}, executor);
CompletableFuture<Void> routeFuture;
if (creatingRoute.isPresent()) {
routeFuture = creatingRoute.get().thenComposeAsync(nul -> {
CancellableCompletableFuture<Void> monitor = pollingMonitor.monitor(this::isRouteRunning, pollingMonitorCheckInterval, pollingMonitorTimeout, TimeUnit.SECONDS);
addFuture(monitor);
return monitor;
}, executor);
} else {
routeFuture = CompletableFuture.completedFuture(null);
}
CompletableFuture<Void> openshiftDefinitionsError = new CompletableFuture<>();
openshiftDefinitions.exceptionally(t -> {
openshiftDefinitionsError.completeExceptionally(t);
return null;
});
CancellableCompletableFuture<Void> isBuildAgentUpFuture = pollingMonitor.monitor(this::isInternalServletAvailable, pollingMonitorCheckInterval, pollingMonitorTimeout, TimeUnit.SECONDS);
addFuture(isBuildAgentUpFuture);
CompletableFuture<RunningEnvironment> runningEnvironmentFuture = CompletableFutureUtils.allOfOrException(podFuture, serviceFuture, routeFuture).thenComposeAsync(nul -> isBuildAgentUpFuture, executor).thenApplyAsync(nul -> RunningEnvironment.createInstance(pod.getMetadata().getName(), Integer.parseInt(environmentConfiguration.getContainerPort()), route.getSpec().getHost(), getPublicEndpointUrl(), getInternalEndpointUrl(), repositorySession, Paths.get(environmentConfiguration.getWorkingDirectory()), this::destroyEnvironment, debugData), executor);
CompletableFuture.anyOf(runningEnvironmentFuture, openshiftDefinitionsError).handleAsync((runningEnvironment, throwable) -> {
if (throwable != null) {
logger.info("Error while trying to create an OpenShift environment... ", throwable);
cancelAndClearMonitors();
// no more retries, execute the onError consumer
if (retries == 0) {
logger.info("No more retries left, giving up!");
onError.accept(new Exception(getPrettierErrorMessageFromThrowable(throwable, true), throwable));
} else {
PodFailedStartException podFailedStartExc = null;
if (throwable instanceof PodFailedStartException) {
podFailedStartExc = (PodFailedStartException) throwable;
} else if (throwable.getCause() instanceof PodFailedStartException) {
podFailedStartExc = (PodFailedStartException) throwable.getCause();
}
if (podFailedStartExc != null && !Arrays.asList(POD_RETRYABLE_STATUSES).contains(podFailedStartExc.getPodStatus())) {
logger.info("The detected pod error status '{}' is not considered among the ones to be retried, giving up!", podFailedStartExc.getPodStatus());
// the status is not to be retried
onError.accept(new Exception(getPrettierErrorMessageFromThrowable(throwable, false), throwable));
} else {
if (!cancelRequested) {
logger.warn("Creating build environment failed with error '{}'! Retrying ({} retries left)...", throwable, retries);
retryEnvironment(onComplete, onError, retries);
} else {
logger.info("Build was cancelled, not retrying environment!");
}
}
}
} else {
logger.info("Environment successfully initialized. Pod [{}]; Service [{}].", pod.getMetadata().getName(), service.getMetadata().getName());
// openshiftDefinitionsError
onComplete.accept((RunningEnvironment) runningEnvironment);
// completes only with error
}
gaugeMetric.ifPresent(g -> g.incrementMetric(METRICS_POD_STARTED_SUCCESS_KEY));
return null;
}, executor);
}
use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.
the class DestroyableEnvironmentMock method build.
public static DestroyableEnvironment build() {
RepositorySession repositorySession = new RepositorySessionMock();
Path workingDir = Paths.get("/root");
return RunningEnvironment.createInstance("1", 8080, "localhost", "build/agent/url", "internal,build/agent/url", repositorySession, workingDir, () -> {
}, new DebugData(false));
}
use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.
the class BuildGroupIncludesProductVersionGroupTest method verifyGroupComposition_ProductVersion_NoConfSet.
@Test
public void verifyGroupComposition_ProductVersion_NoConfSet() throws Exception {
// create a dummy non-chained build execution and repo session based on it
BuildExecution execution = new TestBuildExecution("build_myproject_12345");
Indy indy = driver.getIndy(accessToken);
RepositorySession repositoryConfiguration = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
String repoId = repositoryConfiguration.getBuildRepositoryId();
assertThat(repoId, equalTo(execution.getBuildContentId()));
// check that the build group includes:
// - the build's hosted repo
// - the product version repo group
// - the "shared-releases" repo group
// - the "shared-imports" repo
// - the public group
// ...in that order
Group buildGroup = indy.stores().load(new StoreKey(MAVEN_PKG_KEY, StoreType.group, repoId), Group.class);
System.out.printf("Constituents:\n %s\n", join(buildGroup.getConstituents(), "\n "));
assertGroupConstituents(buildGroup, new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, execution.getBuildContentId()), new StoreKey(MAVEN_PKG_KEY, StoreType.group, IndyRepositoryConstants.COMMON_BUILD_GROUP_CONSTITUENTS_GROUP));
}
Aggregations