use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.
the class VerifyBuildRepoPromotionToUntestedBuildsGroupTest method extractBuildArtifactsTriggersBuildRepoPromotionToChainGroup.
@Test
public void extractBuildArtifactsTriggersBuildRepoPromotionToChainGroup() 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 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);
StoreKey hostedKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, buildId);
// simulate a build deploying a file.
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 pnc-builds
// group.
RepositoryManagerResult result = session.extractBuildArtifacts(true);
assertThat(result.getCompletionStatus(), equalTo(CompletionStatus.SUCCESS));
// 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()));
// end result: the pnc-builds group should contain the build hosted repo.
StoreKey pncBuildsKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, PNC_BUILDS);
assertThat(indy.content().exists(pncBuildsKey, path), equalTo(true));
}
use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession 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.spi.repositorymanager.model.RepositorySession 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.spi.repositorymanager.model.RepositorySession 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.model.RepositorySession in project pnc by project-ncl.
the class DefaultBuildExecutor method retrieveRepositoryManagerResults.
private Void retrieveRepositoryManagerResults(DefaultBuildExecutionSession buildExecutionSession) {
try {
if (!buildExecutionSession.hasFailed() && !buildExecutionSession.isCanceled()) {
ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER.toString(), "Collecting results from repository manager ...");
buildExecutionSession.setStatus(BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER);
RunningEnvironment runningEnvironment = buildExecutionSession.getRunningEnvironment();
if (runningEnvironment == null) {
return null;
}
RepositorySession repositorySession = runningEnvironment.getRepositorySession();
if (repositorySession == null) {
return null;
}
RepositoryManagerResult repositoryManagerResult = repositorySession.extractBuildArtifacts(true);
buildExecutionSession.setRepositoryManagerResult(repositoryManagerResult);
if (repositoryManagerResult.getCompletionStatus().isFailed()) {
buildExecutionSession.setStatus(BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER_COMPLETED_WITH_ERROR);
} else {
buildExecutionSession.setStatus(BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER_COMPLETED_SUCCESS);
}
}
} catch (Throwable e) {
throw new BuildProcessException(e, buildExecutionSession.getRunningEnvironment());
} finally {
ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.COLLECTING_RESULTS_FROM_REPOSITORY_MANAGER.toString(), "Collected results from repository manager.");
}
return null;
}
Aggregations