Search in sources :

Example 1 with PathsPromoteRequest

use of org.commonjava.indy.promote.model.PathsPromoteRequest 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 2 with PathsPromoteRequest

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

the class ValidationRequest method getSourcePaths.

public synchronized Set<String> getSourcePaths(boolean includeMetadata, boolean includeChecksums) throws PromotionValidationException {
    if (requestPaths == null) {
        Set<String> paths = null;
        if (promoteRequest instanceof PathsPromoteRequest) {
            paths = ((PathsPromoteRequest) promoteRequest).getPaths();
        }
        if (paths == null) {
            ArtifactStore store = null;
            try {
                store = tools.getArtifactStore(promoteRequest.getSource());
            } catch (IndyDataException e) {
                throw new PromotionValidationException("Failed to retrieve source ArtifactStore: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
            }
            if (store != null) {
                try {
                    paths = new HashSet<>();
                    listRecursively(store, "/", paths);
                } catch (IndyWorkflowException e) {
                    throw new PromotionValidationException("Failed to list paths in source: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
                }
            }
        }
        requestPaths = paths;
    }
    if (!includeMetadata || !includeChecksums) {
        Predicate<String> filter = (path) -> (includeMetadata || !path.matches(".+/maven-metadata\\.xml(\\.(md5|sha[0-9]+))?")) && (includeChecksums || !path.matches(".+\\.(md5|sha[0-9]+)"));
        return requestPaths.stream().filter(filter).collect(Collectors.toSet());
    }
    return requestPaths;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Predicate(java.util.function.Predicate) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) ValidationRuleSet(org.commonjava.indy.promote.model.ValidationRuleSet) List(java.util.List) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreResource(org.commonjava.indy.content.StoreResource) PromotionValidationTools(org.commonjava.indy.promote.validate.PromotionValidationTools) PromoteRequest(org.commonjava.indy.promote.model.PromoteRequest) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreKey(org.commonjava.indy.model.core.StoreKey) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException)

Example 3 with PathsPromoteRequest

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

the class FoloTrackingAdjustListener method handlePathsPromoteComplete.

private void handlePathsPromoteComplete(PathsPromoteResult promoteResult) {
    String error = promoteResult.getError();
    if (error != null) {
        logger.trace("Error in promoteResult, skip adjust");
        return;
    }
    Set<String> paths = promoteResult.getCompletedPaths();
    if (paths.isEmpty()) {
        logger.trace("No completedPaths, skip adjust");
        return;
    }
    PathsPromoteRequest req = promoteResult.getRequest();
    StoreKey source = req.getSource();
    StoreKey target = req.getTarget();
    TrackingKey trackingKey = getTrackingKey(source);
    if (trackingKey == null) {
        logger.trace("No tracking key found to: {}", source);
        return;
    }
    // Get the sealed record, client MUST seal the record before promote
    TrackedContent trackedContent = recordManager.get(trackingKey);
    if (trackedContent == null) {
        logger.trace("No sealed record found, trackingKey: {}", trackingKey);
        return;
    }
    adjustTrackedContent(trackedContent, source, target);
    recordManager.replaceTrackingRecord(trackedContent);
}
Also used : TrackedContent(org.commonjava.indy.folo.model.TrackedContent) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 4 with PathsPromoteRequest

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

the class PromoteDryRunAsyncTest method run.

@Test
public void run() throws Exception {
    PathsPromoteResult result = client.module(IndyPromoteClientModule.class).promoteByPath(getAsyncRequest(new PathsPromoteRequest(source.getKey(), target.getKey()).setDryRun(true)));
    assertEquals(result.getResultCode(), ACCEPTED);
    result = getAsyncPromoteResult(PathsPromoteResult.class);
    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(), first), equalTo(false));
    assertThat(client.content().exists(target.getKey(), 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 5 with PathsPromoteRequest

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

the class PromoteIgnoreMissingNonDecoratableTest method run.

@Test
public void run() throws Exception {
    final PathsPromoteResult result = client.module(IndyPromoteClientModule.class).promoteByPath(new PathsPromoteRequest(source.getKey(), target.getKey(), first, second, nonDecoratablePath));
    final Set<String> pending = result.getPendingPaths();
    assertThat(pending.isEmpty(), equalTo(true));
    final Set<String> completed = result.getCompletedPaths();
    assertThat(completed, notNullValue());
    assertThat(completed.size(), equalTo(2));
    // the missing non-decoratable path should be skipped
    final Set<String> skipped = result.getSkippedPaths();
    assertThat(skipped, notNullValue());
    assertThat(skipped.contains(nonDecoratablePath), equalTo(true));
    assertThat(result.getError(), nullValue());
    assertThat(client.content().exists(target.getKey(), first), equalTo(true));
    assertThat(client.content().exists(target.getKey(), 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)

Aggregations

PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)47 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)40 Test (org.junit.Test)34 IndyPromoteClientModule (org.commonjava.indy.promote.client.IndyPromoteClientModule)15 Category (org.junit.experimental.categories.Category)10 InputStream (java.io.InputStream)8 StoreKey (org.commonjava.indy.model.core.StoreKey)8 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 HashSet (java.util.HashSet)6 IndyDataException (org.commonjava.indy.data.IndyDataException)6 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)6 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)6 IOException (java.io.IOException)5 HostedRepository (org.commonjava.indy.model.core.HostedRepository)5 PromotionValidationException (org.commonjava.indy.promote.validate.PromotionValidationException)5 Transfer (org.commonjava.maven.galley.model.Transfer)5 ExecutionException (java.util.concurrent.ExecutionException)4 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)4 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)4