skipcheck

TM1 client · Docs · More services

GitService

import io.skipcheck.tm1.client.service.git.GitService;

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 and pull make a plan saying what would happen (the files, or the operations, such as Skip Dimensions('Region')), and execute 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 and status, 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 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 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));

Members

GitService constructorA service sending its requests through session.
initTies the model to a repository.
uninitUnties the model from its repository.
statusThe tie, and what's on the remote.
pushPlans a commit of the model's changes on top of branch.
pullPlans bringing the model up to branch.
deployTies a server not yet tied to a repository, and pulls branch into it, in one step.
plansGET GitPlans, streamed.
planOne of this session's plans, by ID.
executeCarries out a plan, pushing its files or pulling its operations.

GitService

constructor
GitService(Tm1Session session)

A service sending its requests through session.

Parameters

session
the session

init

Mono<Git> init(String url, String deployment, GitCredentials credentials, boolean force, 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

TM1 REST ActionImport GitInit

uninit

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

TM1 REST ActionImport GitUninit

status

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

TM1 REST ActionImport GitStatus

push

Mono<GitPushPlan> push(String branch, 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 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

TM1 REST ActionImport GitPush

pull

Mono<GitPullPlan> pull(String branch, GitCredentials credentials, 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 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

TM1 REST ActionImport GitPull

deploy

Mono<Void> deploy(String url, String branch, String deployment, GitCredentials credentials, boolean force, 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 then shows the commit

TM1 REST ActionImport GitDeploy

plans

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

TM1 REST EntitySet GitPlans

plan

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)

TM1 REST EntitySet GitPlans

execute

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, pull or plans

Returns

completes when it's done

Also in the Javadoc.