Class GitService

java.lang.Object
io.skipcheck.tm1.client.service.git.GitService

public final class GitService extends Object
TM1 Git (schema 11.5.0): ties the model to a Git repository, pushes its objects there as JSON files (dimensions/Region.json, …), and pulls them back, on this server or another.

Pushing and pulling are two steps: push(String, String, GitCommitDetails, GitCredentials, boolean) and pull(String, GitCredentials, GitPlanExecutionMode, boolean) make a plan saying what would happen (the files, or the operations, such as Skip Dimensions('Region')), and execute(GitPlan) carries it out.

What TM1 (11.8) does here that you might not expect:

  • A plan belongs to the TM1 session that made it: another session can't see it or run it. Executing a plan uses it up; it's gone afterwards.
  • The remote needs a commit on the branch to start from: TM1 can't make a repository's first commit, and pushing when the model hasn't changed is refused too (both "Cannot create bare commit").
  • A local file:// remote works for init(String, String, GitCredentials, boolean, GitConfigurationPatch) and status(GitCredentials), but not for pushing or pulling ("shallow fetch is not supported by the local transport"); use https://, ssh:// or git://. TM1 also refuses a local repository its own user doesn't own.
  • deploy(String, String, String, GitCredentials, boolean, GitConfigurationPatch) is refused while Git is initialized ("Cannot re-deploy"): it's for a server not yet tied to the repository.
  • A pull compares commits, not the model: it plans the changes between the commit last deployed and the branch, so an object deleted on the server since is skipped (Skip Dimensions('Region')), not brought back. deploy(String, String, String, GitCredentials, boolean, GitConfigurationPatch) brings the whole branch.
  • The first pull after the remote moves on still plans the commit TM1 had; the next pull plans the new one. Check the plan's Commit before executing it.

Tie the model to a repository:

// The remote's branch must already have a commit: TM1 can't make the first one
GitCredentials credentials = GitCredentials.password("tm1-bot", token);
return tm1.git().init("https://git.example.com/finance/model.git", "dev", credentials, false, null);

Push the model's changes:

// Plan the commit, look at the files it would push, then push them
GitCommitDetails commit = new GitCommitDetails("Add the Region dimension", "Ada Analyst", "ada@example.com");
return tm1.git()
	.push("main", null, commit, credentials, false)
	.flatMap(plan -> plan.sourceFiles() == null || plan.sourceFiles().isEmpty() ? Mono.empty()
			: tm1.git().execute(plan));

Pull a branch, once the plan is for the commit wanted:

// TM1 11.8 plans the commit it had on the first pull after the remote moves on:
// pull again until the plan is for the commit wanted, then carry it out
return tm1.git()
	.pull("main", credentials, null, false)
	.filter(plan -> plan.commit() != null && newest.startsWith(plan.commit().id()))
	.repeatWhenEmpty(2, attempts -> attempts)
	.flatMap(plan -> tm1.git().execute(plan));
  • Constructor Details

    • GitService

      public GitService(Tm1Session session)
      A service sending its requests through session.
      Parameters:
      session - the session
  • Method Details

    • init

      @Tm1Endpoint("ActionImport GitInit") public reactor.core.publisher.Mono<Git> init(String url, @Nullable String deployment, GitCredentials credentials, boolean force, @Nullable GitConfigurationPatch config)
      GitInit: ties the model to a repository.
      Parameters:
      url - the remote's URL
      deployment - the deployment's name, such as dev, or null for none
      credentials - how to sign in to the remote
      force - whether to replace an existing tie
      config - the Git configuration, or null for TM1's
      Returns:
      the tie: URL, deployment, deployed commit, and the remote's branches and tags
    • uninit

      @Tm1Endpoint("ActionImport GitUninit") public reactor.core.publisher.Mono<Void> uninit(boolean force)
      GitUninit: unties the model from its repository. The model is left as it is.
      Parameters:
      force - whether to untie it even with a plan waiting
      Returns:
      completes when it's untied
    • status

      @Tm1Endpoint("ActionImport GitStatus") public reactor.core.publisher.Mono<Git> status(GitCredentials credentials)
      GitStatus: the tie, and what's on the remote. Fails with a Tm1BadRequestException if Git isn't initialized.
      Parameters:
      credentials - how to sign in to the remote
      Returns:
      the tie
    • push

      @Tm1Endpoint("ActionImport GitPush") public reactor.core.publisher.Mono<GitPushPlan> push(String branch, @Nullable String newBranch, GitCommitDetails commit, GitCredentials credentials, boolean force)
      GitPush: plans a commit of the model's changes on top of branch. The plan lists the files; execute(GitPlan) pushes them.
      Parameters:
      branch - the branch to start from, which must exist on the remote
      newBranch - the branch to push to, or null for branch
      commit - the commit's message and author
      credentials - how to sign in to the remote
      force - whether to push even if the remote moved on
      Returns:
      the plan
    • pull

      @Tm1Endpoint("ActionImport GitPull") public reactor.core.publisher.Mono<GitPullPlan> pull(String branch, GitCredentials credentials, @Nullable GitPlanExecutionMode mode, boolean force)
      GitPull: plans bringing the model up to branch. Pull again if the plan's Commit isn't the branch's newest: TM1 (11.8) lags a pull behind the remote. The plan lists the operations; execute(GitPlan) carries them out.
      Parameters:
      branch - the branch to pull
      credentials - how to sign in to the remote
      mode - one commit or each commit in turn, or null for TM1's (SingleCommit)
      force - whether to pull over local changes
      Returns:
      the plan
    • deploy

      @Tm1Endpoint("ActionImport GitDeploy") public reactor.core.publisher.Mono<Void> deploy(String url, String branch, @Nullable String deployment, GitCredentials credentials, boolean force, @Nullable GitConfigurationPatch config)
      GitDeploy: ties a server not yet tied to a repository, and pulls branch into it, in one step. Refused while Git is initialized.
      Parameters:
      url - the remote's URL
      branch - the branch to deploy
      deployment - the deployment's name, or null for none
      credentials - how to sign in to the remote
      force - whether to deploy over local changes
      config - the Git configuration, or null for TM1's
      Returns:
      completes when it's deployed; status(GitCredentials) then shows the commit
    • plans

      @Tm1Endpoint("EntitySet GitPlans") public reactor.core.publisher.Flux<GitPlan> plans(ODataQuery query)
      GET GitPlans, streamed: this session's plans not yet executed. Fails with a Tm1BadRequestException if Git isn't initialized.
      Parameters:
      query - what to select and filter
      Returns:
      the plans, each a GitPushPlan or GitPullPlan
    • plan

      @Tm1Endpoint("EntitySet GitPlans") public reactor.core.publisher.Mono<GitPlan> plan(String id)
      One of this session's plans, by ID. TM1 (11.8) sends no @odata.type for GitPlans('id'), so it couldn't be told apart as a push or a pull; the list says, so the plan is found there.
      Parameters:
      id - the plan's ID
      Returns:
      the plan, or empty if this session has none by that ID (an executed plan is gone)
    • execute

      @Tm1Endpoint("Action GitPushPlan/Execute") @Tm1Endpoint("Action GitPullPlan/Execute") public reactor.core.publisher.Mono<Void> execute(GitPlan plan)
      tm1.Execute: carries out a plan, pushing its files or pulling its operations. The plan is used up.
      Parameters:
      plan - the plan, from push(String, String, GitCommitDetails, GitCredentials, boolean), pull(String, GitCredentials, GitPlanExecutionMode, boolean) or plans(ODataQuery)
      Returns:
      completes when it's done