Search in sources :

Example 6 with PathsPromoteResult

use of org.commonjava.indy.promote.model.PathsPromoteResult in project indy by Commonjava.

the class ArtifactRefs_PromoteWithParent_RuleTest method run.

@Test
@Category(EventDependent.class)
public void run() throws Exception {
    String child = "org/foo/child/1/child-1.pom";
    String parent = "org/foo/parent/1/parent-1.pom";
    deployResource(child, PREFIX + "child.pom.xml");
    deployResource(parent, PREFIX + "parent.pom.xml");
    waitForEventPropagation();
    InputStream stream = client.content().get(source.getKey(), child);
    String childRerived = IOUtils.toString(stream);
    stream.close();
    logger.debug("promote with parent in source: child content: {}", childRerived);
    assertThat(childRerived, containsString("<artifactId>child</artifactId>"));
    stream = client.content().get(source.getKey(), parent);
    String parentRetrived = IOUtils.toString(stream);
    stream.close();
    logger.debug("promote with parent in source: parent content: {}", parentRetrived);
    assertThat(parentRetrived, containsString("<artifactId>parent</artifactId>"));
    PathsPromoteRequest request = new PathsPromoteRequest(source.getKey(), target.getKey(), child, parent);
    PathsPromoteResult result = module.promoteByPath(request);
    assertThat(result, notNullValue());
    ValidationResult validations = result.getValidations();
    System.out.println(validations);
    assertThat(validations, notNullValue());
    assertThat(validations.isValid(), equalTo(true));
    stream = client.content().get(target.getKey(), child);
    childRerived = IOUtils.toString(stream);
    stream.close();
    logger.debug("promote with parent in target: child content: {}", childRerived);
    assertThat(childRerived, containsString("<artifactId>child</artifactId>"));
    stream = client.content().get(target.getKey(), parent);
    parentRetrived = IOUtils.toString(stream);
    stream.close();
    logger.debug("promote with parent in target: parent content: {}", parentRetrived);
    assertThat(parentRetrived, containsString("<artifactId>parent</artifactId>"));
}
Also used : InputStream(java.io.InputStream) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 7 with PathsPromoteResult

use of org.commonjava.indy.promote.model.PathsPromoteResult in project indy by Commonjava.

the class PromoteDryRunTest method run.

@Test
public void run() throws Exception {
    final PathsPromoteResult result = client.module(IndyPromoteClientModule.class).promoteByPath(new PathsPromoteRequest(source.getKey(), target.getKey()).setDryRun(true));
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    final Set<String> completed = result.getCompletedPaths();
    assertThat(completed == null || completed.isEmpty(), equalTo(true));
    final Set<String> pending = result.getPendingPaths();
    assertThat(pending, notNullValue());
    assertThat(pending.size(), equalTo(2));
    assertThat(result.getError(), nullValue());
    assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(false));
    assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(false));
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) Test(org.junit.Test)

Example 8 with PathsPromoteResult

use of org.commonjava.indy.promote.model.PathsPromoteResult in project indy by Commonjava.

the class PromoteWithPurgeThenRollbackTest method run.

@Test
public void run() throws Exception {
    PathsPromoteResult result = client.module(IndyPromoteClientModule.class).promoteByPath(new PathsPromoteRequest(source.getKey(), target.getKey()).setPurgeSource(true));
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    Set<String> pending = result.getPendingPaths();
    assertThat(pending == null || pending.isEmpty(), equalTo(true));
    Set<String> completed = result.getCompletedPaths();
    assertThat(completed, notNullValue());
    assertThat(completed.size(), equalTo(2));
    assertThat(result.getError(), nullValue());
    result = client.module(IndyPromoteClientModule.class).rollbackPathPromote(result);
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    completed = result.getCompletedPaths();
    assertThat(completed == null || completed.isEmpty(), equalTo(true));
    pending = result.getPendingPaths();
    assertThat(pending, notNullValue());
    assertThat(pending.size(), equalTo(2));
    assertThat(result.getError(), nullValue());
    assertThat(client.content().exists(target.getKey().getType(), target.getName(), first), equalTo(false));
    assertThat(client.content().exists(target.getKey().getType(), target.getName(), second), equalTo(false));
    assertThat(client.content().exists(source.getKey().getType(), source.getName(), first), equalTo(true));
    assertThat(client.content().exists(source.getKey().getType(), source.getName(), second), equalTo(true));
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) Test(org.junit.Test)

Example 9 with PathsPromoteResult

use of org.commonjava.indy.promote.model.PathsPromoteResult in project indy by Commonjava.

the class IndyPromoteClientModule method promoteByPath.

public PathsPromoteResult promoteByPath(final StoreType srcType, final String srcName, final StoreType targetType, final String targetName, final boolean purgeSource, final String... paths) throws IndyClientException {
    final PathsPromoteRequest req = new PathsPromoteRequest(new StoreKey(srcType, srcName), new StoreKey(targetType, targetName), new HashSet<String>(Arrays.asList(paths))).setPurgeSource(purgeSource);
    final PathsPromoteResult result = http.postWithResponse(PATHS_PROMOTE_PATH, req, PathsPromoteResult.class, HttpStatus.SC_OK);
    return result;
}
Also used : PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) StoreKey(org.commonjava.indy.model.core.StoreKey) HashSet(java.util.HashSet)

Example 10 with PathsPromoteResult

use of org.commonjava.indy.promote.model.PathsPromoteResult in project indy by Commonjava.

the class PromotionManagerTest method rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource.

@Test
public void rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource() throws Exception {
    final HostedRepository source = new HostedRepository(MAVEN_PKG_KEY, "source");
    storeManager.storeArtifactStore(source, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
    final String first = "/first/path";
    final String second = "/second/path";
    contentManager.store(source, first, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
    contentManager.store(source, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
    final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
    storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
    PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()).setPurgeSource(true), FAKE_BASE_URL);
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    Set<String> pending = result.getPendingPaths();
    assertThat(pending == null || pending.isEmpty(), equalTo(true));
    Set<String> completed = result.getCompletedPaths();
    assertThat(completed, notNullValue());
    assertThat(completed.size(), equalTo(2));
    assertThat(result.getError(), nullValue());
    result = manager.rollbackPathsPromote(result);
    assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
    assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
    completed = result.getCompletedPaths();
    assertThat(completed == null || completed.isEmpty(), equalTo(true));
    pending = result.getPendingPaths();
    assertThat(pending, notNullValue());
    assertThat(pending.size(), equalTo(2));
    assertThat(result.getError(), nullValue());
    Transfer ref = downloadManager.getStorageReference(target, first);
    assertThat(ref.exists(), equalTo(false));
    ref = downloadManager.getStorageReference(target, second);
    assertThat(ref.exists(), equalTo(false));
    ref = downloadManager.getStorageReference(source, first);
    assertThat(ref.exists(), equalTo(true));
    ref = downloadManager.getStorageReference(source, second);
    assertThat(ref.exists(), equalTo(true));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) Transfer(org.commonjava.maven.galley.model.Transfer) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Aggregations

PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)23 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)18 Test (org.junit.Test)14 Transfer (org.commonjava.maven.galley.model.Transfer)10 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)7 HostedRepository (org.commonjava.indy.model.core.HostedRepository)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 StoreKey (org.commonjava.indy.model.core.StoreKey)5 IndyPromoteClientModule (org.commonjava.indy.promote.client.IndyPromoteClientModule)5 HashSet (java.util.HashSet)4 ValidationResult (org.commonjava.indy.promote.model.ValidationResult)4 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponse (io.swagger.annotations.ApiResponse)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3