Search in sources :

Example 81 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project pnc by project-ncl.

the class AbstractImportTest method createHostedIfMissing.

private void createHostedIfMissing(StoreKey hostedKey, boolean allowSnapshots, boolean allowReleases) throws IndyClientException {
    if (!indy.stores().exists(hostedKey)) {
        HostedRepository hosted = new HostedRepository(hostedKey.getPackageType(), hostedKey.getName());
        hosted.setAllowSnapshots(allowSnapshots);
        hosted.setAllowReleases(allowReleases);
        indy.stores().create(hosted, "Creating repository " + hostedKey.getName(), HostedRepository.class);
    }
}
Also used : HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 82 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository 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));
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) IndyStoresClientModule(org.commonjava.indy.client.core.module.IndyStoresClientModule) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) BuildRecord(org.jboss.pnc.model.BuildRecord) RunningRepositoryDeletion(org.jboss.pnc.spi.repositorymanager.model.RunningRepositoryDeletion) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 83 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.

the class ProxyResponseHelper method createRepo.

/**
 * Create repositories (group, remote, hosted) when trackingId is present. Otherwise create normal remote
 * repository with specified name.
 *
 * @param trackingId
 * @param url
 * @param name distinct remote repository name. null if trackingId is given
 */
private ProxyCreationResult createRepo(String trackingId, URL url, String name) throws IndyDataException {
    UrlInfo info = new UrlInfo(url.toExternalForm());
    UserPass up = UserPass.parse(ApplicationHeader.authorization, httpRequest, url.getAuthority());
    String baseUrl = getBaseUrl(url, false);
    logger.debug(">>>> Create repo: trackingId=" + trackingId + ", name=" + name);
    ProxyCreationResult result = repoCreator.create(trackingId, name, baseUrl, info, up, LoggerFactory.getLogger(repoCreator.getClass()));
    ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating HTTProx proxy for: " + info.getUrl());
    RemoteRepository remote = result.getRemote();
    if (remote != null) {
        storeManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata());
    }
    HostedRepository hosted = result.getHosted();
    if (hosted != null) {
        storeManager.storeArtifactStore(hosted, changeSummary, false, true, new EventMetadata());
    }
    Group group = result.getGroup();
    if (group != null) {
        storeManager.storeArtifactStore(group, changeSummary, false, true, new EventMetadata());
    }
    return result;
}
Also used : Group(org.commonjava.indy.model.core.Group) UrlInfo(org.commonjava.indy.util.UrlInfo) ProxyCreationResult(org.commonjava.indy.httprox.handler.ProxyCreationResult) UserPass(org.commonjava.indy.subsys.http.util.UserPass) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 84 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.

the class HostedByArcWithIgnoreRootUploadTest method testUploadZipAndCreate.

@Test
public void testUploadZipAndCreate() throws Exception {
    IndyHostedByArchiveClientModule module = client.module(IndyHostedByArchiveClientModule.class);
    final String hostedRepoName = "hosted-zip-ignore";
    HostedRepository repo = module.createRepo(getZipFile(), hostedRepoName, "maven-repository");
    assertThat(repo, notNullValue());
    assertThat(repo.getName(), equalTo(hostedRepoName));
    boolean exists = client.content().exists(repo.getKey(), "org/foo/bar/1.0/foo-bar-1.0.pom");
    assertTrue(exists);
}
Also used : IndyHostedByArchiveClientModule(org.commonjava.indy.hostedbyarc.client.IndyHostedByArchiveClientModule) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 85 with HostedRepository

use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.

the class IndyHostedByArchiveResource method createHostedByZip.

private Response createHostedByZip(final String name, final UriInfo uriInfo, final String ignorePathPrefix, final InputStream fileInput, final HttpServletRequest request, final SecurityContext securityContext) {
    if (!config.isEnabled()) {
        return responseHelper.formatResponse(ApplicationStatus.METHOD_NOT_ALLOWED, "This REST end point is disabled, please enable it first to use");
    }
    logger.info("Checking for existence of: {}:{}:{}", MAVEN_PKG_KEY, StoreType.hosted, name);
    StoreKey storeKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, name);
    if (adminController.exists(storeKey)) {
        return responseHelper.formatResponse(ApplicationStatus.CONFLICT, String.format("Hosted repository %s already exists, can not create it again.", name));
    }
    final String user = securityManager.getUser(securityContext, request);
    final String IGNORED_PATH_PREFIX;
    if (StringUtils.isBlank(ignorePathPrefix)) {
        IGNORED_PATH_PREFIX = "";
    } else {
        IGNORED_PATH_PREFIX = ignorePathPrefix.startsWith("/") ? ignorePathPrefix : "/" + ignorePathPrefix;
    }
    HostedRepository repo;
    try {
        repo = hostedByArchiveManager.createStoreByArc(fileInput, name, user, IGNORED_PATH_PREFIX);
    } catch (IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        return responseHelper.formatResponse(e);
    } finally {
        IOUtils.closeQuietly(fileInput);
    }
    if (repo != null) {
        final URI uri = uriInfo.getBaseUriBuilder().path("/api/admin/stores").path(repo.getPackageType()).path(repo.getType().singularEndpointName()).build(repo.getName());
        return responseHelper.formatCreatedResponseWithJsonEntity(uri, repo);
    } else {
        return responseHelper.formatResponse(new IndyWorkflowException("Hosted creation failed with some unknown error!"));
    }
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Aggregations

HostedRepository (org.commonjava.indy.model.core.HostedRepository)173 Test (org.junit.Test)91 ByteArrayInputStream (java.io.ByteArrayInputStream)84 Group (org.commonjava.indy.model.core.Group)81 InputStream (java.io.InputStream)42 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)41 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)37 Before (org.junit.Before)37 StoreKey (org.commonjava.indy.model.core.StoreKey)34 Transfer (org.commonjava.maven.galley.model.Transfer)23 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)19 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)16 IndyDataException (org.commonjava.indy.data.IndyDataException)15 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)15 PackageMetadata (org.commonjava.indy.pkg.npm.model.PackageMetadata)13 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)12 IndyClientException (org.commonjava.indy.client.core.IndyClientException)11 VersionMetadata (org.commonjava.indy.pkg.npm.model.VersionMetadata)11 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)10 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)9