1   /*
2    * Copyright 2019 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package com.linecorp.centraldogma.server.mirror;
17  
18  import java.io.File;
19  import java.net.URI;
20  import java.time.ZonedDateTime;
21  
22  import javax.annotation.Nullable;
23  
24  import com.cronutils.model.Cron;
25  
26  import com.linecorp.centraldogma.server.MirrorException;
27  import com.linecorp.centraldogma.server.command.CommandExecutor;
28  import com.linecorp.centraldogma.server.storage.repository.Repository;
29  
30  /**
31   * Contains the properties for a mirroring task and performs the task.
32   */
33  public interface Mirror {
34  
35      /**
36       * Returns the schedule for the mirroring task.
37       */
38      Cron schedule();
39  
40      /**
41       * Returns the next execution time of the mirroring task.
42       *
43       * @param lastExecutionTime the last execution time of the mirroring task
44       */
45      ZonedDateTime nextExecutionTime(ZonedDateTime lastExecutionTime);
46  
47      /**
48       * Returns the direction of the mirroring task.
49       */
50      MirrorDirection direction();
51  
52      /**
53       * Returns the authentication credentials which are required when accessing the Git repositories.
54       */
55      MirrorCredential credential();
56  
57      /**
58       * Returns the Central Dogma repository where is supposed to keep the mirrored files.
59       */
60      Repository localRepo();
61  
62      /**
63       * Returns the path in the Central Dogma repository where is supposed to keep the mirrored files.
64       */
65      String localPath();
66  
67      /**
68       * Returns the URI of the Git repository which will be mirrored from.
69       */
70      URI remoteRepoUri();
71  
72      /**
73       * Returns the path of the Git repository where is supposed to be mirrored.
74       */
75      String remotePath();
76  
77      /**
78       * Returns the name of the branch in the Git repository where is supposed to be mirrored.
79       */
80      @Nullable
81      String remoteBranch();
82  
83      /**
84       * Returns a <a href="https://git-scm.com/docs/gitignore">gitignore</a> pattern for the files
85       * which won't be mirrored.
86       */
87      @Nullable
88      String gitignore();
89  
90      /**
91       * Performs the mirroring task.
92       *
93       * @param workDir the local directory where keeps the mirrored files
94       * @param executor the {@link CommandExecutor} which is used to perform operation to the Central Dogma
95       *                 storage
96       * @param maxNumFiles the maximum number of files allowed to the mirroring task. A {@link MirrorException}
97       *                    would be raised if the number of files to be mirrored exceeds it.
98       * @param maxNumBytes the maximum bytes allowed to the mirroring task. A {@link MirrorException} would be
99       *                    raised if the total size of the files to be mirrored exceeds it.
100      */
101     void mirror(File workDir, CommandExecutor executor, int maxNumFiles, long maxNumBytes);
102 }