use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.
the class ValidationRequest method getSourcePaths.
private Set<String> getSourcePaths(boolean includeMetadata, boolean includeChecksums, Predicate<String> filter) throws PromotionValidationException {
if (requestPaths == null) {
Set<String> paths = null;
if (promoteRequest instanceof PathsPromoteRequest) {
paths = ((PathsPromoteRequest) promoteRequest).getPaths();
}
if (paths == null || paths.isEmpty()) {
if (sourceRepository != null) {
try {
paths = new HashSet<>();
// This is used to let galley ignore the NPMPathStorageCalculator handling,
// which will append package.json to a directory transfer and make listing not applicable.
ThreadContext context = ThreadContext.getContext(true);
context.put(RequestContextHelper.IS_RAW_VIEW, Boolean.TRUE);
listRecursively(sourceRepository, "/", paths);
context.put(RequestContextHelper.IS_RAW_VIEW, Boolean.FALSE);
} catch (IndyWorkflowException e) {
throw new PromotionValidationException("Failed to list paths in source: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
}
}
}
requestPaths = paths;
}
if (!includeMetadata || !includeChecksums) {
return requestPaths.stream().filter(filter).collect(Collectors.toSet());
}
return requestPaths;
}
use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.
the class CacheCheckingforPromoteWithRemoteTest method run.
@Test
public // @Category( EventDependent.class )
void run() throws Exception {
/* @formatter:off */
final String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project>\n" + " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <version>1</version>\n" + "</project>\n";
/* @formatter:on */
final String pomUrl = server.formatUrl(rId, pomPath);
server.expect(pomUrl, 200, content);
assertContent(getContent(g), content);
assertTrue(StringUtils.isBlank(getContent(h)));
PathsPromoteRequest request = new PathsPromoteRequest(r.getKey(), h.getKey(), pomPath);
PathsPromoteResult result = module.promoteByPath(request);
assertThat(result, notNullValue());
ValidationResult validations = result.getValidations();
assertThat(validations, notNullValue());
Map<String, String> validatorErrors = validations.getValidatorErrors();
assertThat(validatorErrors, notNullValue());
System.out.println(String.format("[errors] validation errors: %s", validatorErrors));
// FIXME: some way to check cache directly but not through client
assertContent(getContent(h), content);
}
use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.
the class GroupNFCEntryClearedOnByPathPromoteTest method run.
@Test
@Category(EventDependent.class)
public void run() throws Exception {
try (InputStream stream = client.content().get(new StoreKey(MAVEN_PKG_KEY, group, GROUP_G_NAME), PATH)) {
assertThat("Path should not yet be available from group!", stream, nullValue());
}
// NOTE: This really shouldn't be needed, but I was having trouble getting the NFC entry registered without it.
try (InputStream stream = client.content().get(new StoreKey(MAVEN_PKG_KEY, group, GROUP_G_NAME), PATH)) {
assertThat("NFC: Path should be marked as missing!", stream, nullValue());
}
PathsPromoteRequest request = new PathsPromoteRequest(b.getKey(), a.getKey(), PATH);
PathsPromoteResult response = promote.promoteByPath(request);
assertThat(response.getError(), nullValue());
waitForEventPropagation();
// If you want to see that clearing the NFC works, uncomment this:
// try (InputStream stream = client.content().get( new StoreKey( MAVEN_PKG_KEY, group, GROUP_G_NAME ), PATH ))
// {
// assertThat( "NFC: Path should be marked as missing!", stream,
// nullValue() );
// }
//
//
// client.module( IndyNfcClientModule.class ).clearAll();
assertContent(g, PATH, POM_CONTENT);
}
use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.
the class PromotionManagerTest method rollback_PushTwoArtifactsToHostedRepo_PromoteFailedAndAutoRollback.
/**
* To make the promotion fail, we just add a same path to target and set the request failWhenExists.
*/
@Test
public void rollback_PushTwoArtifactsToHostedRepo_PromoteFailedAndAutoRollback() throws Exception {
prepareHostedReposAndTwoPaths();
contentManager.store(target, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
PathsPromoteRequest request = new PathsPromoteRequest(source.getKey(), target.getKey());
request.setFailWhenExists(true);
PathsPromoteResult result = manager.promotePaths(request, FAKE_BASE_URL);
Set<String> pending = result.getPendingPaths();
assertThat(pending, notNullValue());
assertThat(pending.size(), equalTo(2));
Set<String> completed = result.getCompletedPaths();
assertThat(completed.size(), equalTo(0));
assertThat(result.getError(), notNullValue());
System.out.println(">>> " + result.getError());
verifyExistence(false, true, true, true);
}
use of org.commonjava.indy.promote.model.PathsPromoteRequest in project indy by Commonjava.
the class PromotionManagerTest method rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource.
@Test
public void rollback_PurgeSource_PushTwoArtifactsToHostedRepo_PromoteSuccessThenRollback_VerifyContentInSource() throws Exception {
prepareHostedReposAndTwoPaths();
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());
verifyExistence(false, false, true, true);
}
Aggregations