Search in sources :

Example 1 with EventMonitors

use of com.google.copybara.monitor.EventMonitor.EventMonitors in project copybara by google.

the class Workflow method run.

@Override
public void run(Path workdir, ImmutableList<String> sourceRefs) throws RepoException, IOException, ValidationException {
    if (sourceRefs.size() > 1) {
        throw new CommandLineException(String.format("Workflow does not support multiple source_ref arguments yet: %s", ImmutableList.copyOf(sourceRefs)));
    }
    @Nullable String sourceRef = sourceRefs.size() == 1 ? sourceRefs.get(0) : null;
    validateFlags();
    try (ProfilerTask ignore = profiler().start("run/" + name)) {
        console.progress("Getting last revision: " + "Resolving " + ((sourceRef == null) ? "origin reference" : sourceRef));
        O resolvedRef = generalOptions.repoTask("origin.resolve_source_ref", () -> origin.resolve(sourceRef));
        logger.log(Level.INFO, String.format("Running Copybara for workflow '%s' and ref '%s': %s", name, resolvedRef.asString(), this.toString()));
        logger.log(Level.INFO, String.format("Using working directory : %s", workdir));
        ImmutableList.Builder<DestinationEffect> allEffects = ImmutableList.builder();
        WorkflowRunHelper<O, D> helper = newRunHelper(workdir, resolvedRef, sourceRef, event -> {
            allEffects.addAll(event.getDestinationEffects());
            eventMonitors().dispatchEvent(m -> m.onChangeMigrationFinished(event));
        });
        try (ProfilerTask ignored = profiler().start(mode.toString().toLowerCase())) {
            mode.run(helper);
        } finally {
            if (!getGeneralOptions().dryRunMode) {
                try (ProfilerTask ignored = profiler().start("after_all_migration")) {
                    ImmutableList<DestinationEffect> effects = allEffects.build();
                    ImmutableList<DestinationEffect> resultEffects = runHooks(effects, getAfterAllMigrationActions(), // Only do this once for all the actions
                    memoized(c -> helper.getOriginReader().getFeedbackEndPoint(c)), // Only do this once for all the actions
                    memoized(c -> helper.getDestinationWriter().getFeedbackEndPoint(c)), resolvedRef);
                    if (effects.size() != resultEffects.size()) {
                        console.warn("Effects where created in after_all_migrations, but they are ignored.");
                    }
                }
            }
        }
    }
}
Also used : Writer(com.google.copybara.Destination.Writer) ConfigFile(com.google.copybara.config.ConfigFile) MigrationReference(com.google.copybara.Info.MigrationReference) ValidationException.checkCondition(com.google.copybara.exception.ValidationException.checkCondition) RepoException(com.google.copybara.exception.RepoException) FinishHookContext(com.google.copybara.feedback.FinishHookContext) Callable(java.util.concurrent.Callable) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ChangesResponse(com.google.copybara.Origin.Reader.ChangesResponse) TokenType(com.google.copybara.templatetoken.Token.TokenType) ImmutableList(com.google.common.collect.ImmutableList) Path(java.nio.file.Path) Profiler(com.google.copybara.profiler.Profiler) Nullable(javax.annotation.Nullable) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) CHANGE_REQUEST_FROM_SOT(com.google.copybara.WorkflowMode.CHANGE_REQUEST_FROM_SOT) Reader(com.google.copybara.Origin.Reader) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) Identity(com.google.copybara.util.Identity) ImmutableMap(com.google.common.collect.ImmutableMap) Migration(com.google.copybara.config.Migration) Token(com.google.copybara.templatetoken.Token) Action(com.google.copybara.action.Action) MoreObjects(com.google.common.base.MoreObjects) ValidationException(com.google.copybara.exception.ValidationException) SkylarkConsole(com.google.copybara.transform.SkylarkConsole) Set(java.util.Set) LazyResourceLoader.memoized(com.google.copybara.LazyResourceLoader.memoized) Console(com.google.copybara.util.console.Console) IOException(java.io.IOException) EventMonitors(com.google.copybara.monitor.EventMonitor.EventMonitors) DestinationStatus(com.google.copybara.Destination.DestinationStatus) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) CHANGE_REQUEST(com.google.copybara.WorkflowMode.CHANGE_REQUEST) Authoring(com.google.copybara.authoring.Authoring) Glob(com.google.copybara.util.Glob) List(java.util.List) ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent) Paths(java.nio.file.Paths) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CommandLineException(com.google.copybara.exception.CommandLineException) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) ImmutableList(com.google.common.collect.ImmutableList) CommandLineException(com.google.copybara.exception.CommandLineException) Nullable(javax.annotation.Nullable)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 DestinationStatus (com.google.copybara.Destination.DestinationStatus)1 Writer (com.google.copybara.Destination.Writer)1 MigrationReference (com.google.copybara.Info.MigrationReference)1 LazyResourceLoader.memoized (com.google.copybara.LazyResourceLoader.memoized)1 Reader (com.google.copybara.Origin.Reader)1 ChangesResponse (com.google.copybara.Origin.Reader.ChangesResponse)1 CHANGE_REQUEST (com.google.copybara.WorkflowMode.CHANGE_REQUEST)1 CHANGE_REQUEST_FROM_SOT (com.google.copybara.WorkflowMode.CHANGE_REQUEST_FROM_SOT)1 Action (com.google.copybara.action.Action)1 Authoring (com.google.copybara.authoring.Authoring)1 ConfigFile (com.google.copybara.config.ConfigFile)1 Migration (com.google.copybara.config.Migration)1 CommandLineException (com.google.copybara.exception.CommandLineException)1 RepoException (com.google.copybara.exception.RepoException)1