Search in sources :

Example 36 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class PromotionValidator method validate.

public void validate(PromoteRequest request, ValidationResult result, String baseUrl) throws PromotionValidationException {
    ValidationRuleSet set = validationsManager.getRuleSetMatching(request.getTargetKey());
    Logger logger = LoggerFactory.getLogger(getClass());
    if (set != null) {
        logger.debug("Running validation rule-set for promotion: {}", set.getName());
        result.setRuleSet(set.getName());
        List<String> ruleNames = set.getRuleNames();
        if (ruleNames != null && !ruleNames.isEmpty()) {
            final ArtifactStore store = getRequestStore(request, baseUrl);
            try {
                final ValidationRequest req = new ValidationRequest(request, set, validationTools, store);
                for (String ruleRef : ruleNames) {
                    String ruleName = // flatten in case some path fragment leaks in...
                    new File(ruleRef).getName();
                    ValidationRuleMapping rule = validationsManager.getRuleMappingNamed(ruleName);
                    if (rule != null) {
                        try {
                            logger.debug("Running promotion validation rule: {}", rule.getName());
                            String error = rule.getRule().validate(req);
                            if (StringUtils.isNotEmpty(error)) {
                                logger.debug("{} failed", rule.getName());
                                result.addValidatorError(rule.getName(), error);
                            } else {
                                logger.debug("{} succeeded", rule.getName());
                            }
                        } catch (Exception e) {
                            if (e instanceof PromotionValidationException) {
                                throw (PromotionValidationException) e;
                            }
                            throw new PromotionValidationException("Failed to run validation rule: {} for request: {}. Reason: {}", e, rule.getName(), request, e);
                        }
                    }
                }
            } finally {
                if (needTempRepo(request)) {
                    try {
                        final String changeSum = String.format("Removes the temp remote repo [%s] after promote operation.", store);
                        storeDataMgr.deleteArtifactStore(store.getKey(), new ChangeSummary(ChangeSummary.SYSTEM_USER, changeSum), new EventMetadata().set(ContentManager.SUPPRESS_EVENTS, true));
                        logger.info("Promotion temporary repo {} has been deleted for {}", store.getKey(), request.getSource());
                    } catch (IndyDataException e) {
                        logger.warn("StoreDataManager can not remove artifact stores correctly.", e);
                    }
                }
            }
        }
    } else {
        logger.info("No validation rule-sets are defined for: {}", request.getTargetKey());
    }
}
Also used : ValidationRequest(org.commonjava.indy.promote.validate.model.ValidationRequest) Logger(org.slf4j.Logger) IndyDataException(org.commonjava.indy.data.IndyDataException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ValidationRuleMapping(org.commonjava.indy.promote.validate.model.ValidationRuleMapping) ValidationRuleSet(org.commonjava.indy.promote.model.ValidationRuleSet) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) File(java.io.File)

Example 37 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata 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)

Example 38 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project galley by Commonjava.

the class Transfer method createFile.

public void createFile() throws IOException {
    provider.waitForWriteUnlock(resource);
    if (decorator != null) {
        decorator.decorateCreateFile(this, new EventMetadata());
    }
    provider.createFile(resource);
}
Also used : EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 39 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class GroupDataManagerTCK method createAndDeleteGroup.

@Test
public void createAndDeleteGroup() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final Group grp = new Group("test");
    store(grp);
    manager.deleteArtifactStore(grp.getKey(), summary, new EventMetadata());
    final Group result = manager.query().packageType(MAVEN_PKG_KEY).storeType(Group.class).getByName(grp.getName());
    assertThat(result, nullValue());
}
Also used : Group(org.commonjava.indy.model.core.Group) StoreDataManager(org.commonjava.indy.data.StoreDataManager) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 40 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class RepositoryDataManagerTCK method createAndDeleteCentralRepoProxy.

@Test
public void createAndDeleteCentralRepoProxy() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final RemoteRepository repo = new RemoteRepository("central", "http://repo1.maven.apache.org/maven2/");
    storeRemoteRepository(repo, false);
    manager.deleteArtifactStore(repo.getKey(), summary, new EventMetadata());
    final ArtifactStore result = manager.query().packageType(MAVEN_PKG_KEY).storeType(RemoteRepository.class).getByName(repo.getName());
    assertThat(result, nullValue());
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreDataManager(org.commonjava.indy.data.StoreDataManager) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Aggregations

EventMetadata (org.commonjava.maven.galley.event.EventMetadata)95 Transfer (org.commonjava.maven.galley.model.Transfer)38 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)37 Test (org.junit.Test)37 IndyDataException (org.commonjava.indy.data.IndyDataException)27 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)20 StoreKey (org.commonjava.indy.model.core.StoreKey)18 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)17 Group (org.commonjava.indy.model.core.Group)17 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)15 Logger (org.slf4j.Logger)15 IOException (java.io.IOException)13 Inject (javax.inject.Inject)11 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 Path (javax.ws.rs.Path)10 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)9