Search in sources :

Example 1 with Profiler

use of com.google.copybara.profiler.Profiler in project copybara by google.

the class Feedback method run.

@Override
public void run(Path workdir, @Nullable String sourceRef) throws RepoException, ValidationException {
    // TODO(danielromero): Handle correctly null sourceRefs
    SkylarkConsole console = new SkylarkConsole(generalOptions.console());
    Profiler profiler = generalOptions.profiler();
    try (ProfilerTask ignore = profiler.start("run/" + name)) {
        for (Action action : actions) {
            try (ProfilerTask ignore2 = profiler.start(action.getName())) {
                action.run(new FeedbackContext(origin, destination, sourceRef, console));
            }
        }
    }
    ValidationException.checkCondition(console.getErrorCount() == 0, "%d errors executing the feedback migration", console.getErrorCount());
}
Also used : SkylarkConsole(com.google.copybara.transform.SkylarkConsole) Profiler(com.google.copybara.profiler.Profiler) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask)

Example 2 with Profiler

use of com.google.copybara.profiler.Profiler in project copybara by google.

the class AbstractGitHubApiTest method setUpFamework.

@Before
public void setUpFamework() throws Exception {
    MockitoAnnotations.initMocks(this);
    profiler = new Profiler(Ticker.systemTicker());
    profiler.init(ImmutableList.of(new LogProfilerListener()));
    api = new GitHubApi(getTransport(), profiler);
}
Also used : GitHubApi(com.google.copybara.git.github.api.GitHubApi) Profiler(com.google.copybara.profiler.Profiler) LogProfilerListener(com.google.copybara.profiler.LogProfilerListener) Before(org.junit.Before)

Example 3 with Profiler

use of com.google.copybara.profiler.Profiler in project copybara by google.

the class AbstractGithubApiTest method setUpFamework.

@Before
public void setUpFamework() throws Exception {
    Profiler profiler = new Profiler(Ticker.systemTicker());
    profiler.init(ImmutableList.of(new LogProfilerListener()));
    api = new GithubApi(getTransport(), profiler);
}
Also used : Profiler(com.google.copybara.profiler.Profiler) GithubApi(com.google.copybara.git.github.api.GithubApi) LogProfilerListener(com.google.copybara.profiler.LogProfilerListener) Before(org.junit.Before)

Example 4 with Profiler

use of com.google.copybara.profiler.Profiler 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)

Example 5 with Profiler

use of com.google.copybara.profiler.Profiler in project copybara by google.

the class Mirror method defaultMirror.

private void defaultMirror(GitRepository repo) throws RepoException, ValidationException {
    List<String> fetchRefspecs = refspec.stream().map(r -> r.originToOrigin().toString()).collect(Collectors.toList());
    generalOptions.console().progressFmt("Fetching from %s", origin);
    Profiler profiler = generalOptions.profiler();
    try (ProfilerTask ignore1 = profiler.start("fetch")) {
        repo.fetch(origin, /*prune=*/
        true, /*force=*/
        true, fetchRefspecs, partialFetch);
    }
    if (generalOptions.dryRunMode) {
        generalOptions.console().progressFmt("Skipping push to %s. You can check the" + " commits to push in: %s", destination, repo.getGitDir());
    } else {
        generalOptions.console().progressFmt("Pushing to %s", destination);
        List<Refspec> pushRefspecs = mirrorOptions.forcePush || generalOptions.isForced() ? refspec.stream().map(Refspec::withAllowNoFastForward).collect(Collectors.toList()) : refspec;
        try (ProfilerTask ignore1 = profiler.start("push")) {
            repo.push().prune(prune).withRefspecs(destination, pushRefspecs).run();
        } catch (NonFastForwardRepositoryException e) {
            // multiple refs, and that mirrors, it is better to just fail and tell the user.
            throw new ValidationException("Error pushing some refs because origin is behind:" + e.getMessage(), e);
        }
    }
}
Also used : ConfigFile(com.google.copybara.config.ConfigFile) ActionResult(com.google.copybara.action.ActionResult) Iterables(com.google.common.collect.Iterables) GITHUB_COM(com.google.copybara.git.github.util.GitHubHost.GITHUB_COM) RepoException(com.google.copybara.exception.RepoException) DestinationEffect(com.google.copybara.DestinationEffect) ImmutableList(com.google.common.collect.ImmutableList) Result(com.google.copybara.action.ActionResult.Result) GeneralOptions(com.google.copybara.GeneralOptions) Path(java.nio.file.Path) Profiler(com.google.copybara.profiler.Profiler) Nullable(javax.annotation.Nullable) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) DestinationRef(com.google.copybara.DestinationEffect.DestinationRef) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask) Migration(com.google.copybara.config.Migration) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Action(com.google.copybara.action.Action) ValidationException(com.google.copybara.exception.ValidationException) SkylarkConsole(com.google.copybara.transform.SkylarkConsole) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Dict(net.starlark.java.eval.Dict) List(java.util.List) ChangeMigrationFinishedEvent(com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FluentLogger(com.google.common.flogger.FluentLogger) ValidationException(com.google.copybara.exception.ValidationException) Profiler(com.google.copybara.profiler.Profiler) ProfilerTask(com.google.copybara.profiler.Profiler.ProfilerTask)

Aggregations

Profiler (com.google.copybara.profiler.Profiler)7 Migration (com.google.copybara.config.Migration)3 ProfilerTask (com.google.copybara.profiler.Profiler.ProfilerTask)3 SkylarkConsole (com.google.copybara.transform.SkylarkConsole)3 Before (org.junit.Before)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)2 FakeTicker (com.google.common.testing.FakeTicker)2 Action (com.google.copybara.action.Action)2 ConfigFile (com.google.copybara.config.ConfigFile)2 RepoException (com.google.copybara.exception.RepoException)2 ValidationException (com.google.copybara.exception.ValidationException)2 ChangeMigrationFinishedEvent (com.google.copybara.monitor.EventMonitor.ChangeMigrationFinishedEvent)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2