public class Initializer
extends java.lang.Object
It allows you to define data in JSON files (with associated flat files) that can "replay" operations to a Perforce server or Commons server. The same information can also be queried (quickly) for test scripts.
There are two major stages to initialization. The first stage is seeding the core perforce system. This is where we'll add some basic system users, for example, that all the other services kind of assume are there. We'll also set up the rights of these users. For test environments, we'll also seed a bunch of revisions as well.
The second stage of initialization actually should be run after the Commons webserver is available and initialized (and thus, all the commons metadata exists). Here, we'll run "commons seeding", which will add data from the perspective of commons; new spaces with files added via file valet, etc.
Data is indicated by creating JSON files and loading them such that a
resource loader can find them either under the path
initializer/perforce
or initializer/commons
.
The initializer runs in a single thread, in order.
The initializer can be run via the command line. It expects that the p4d instance to seed is already configured. The configuration can be loaded via a single config file or via overrides.
Alternatively, the Initializer can be run within your environment. This expects that the p4java_commons connections respect the user switch provided by the InitializerConnections interface.
Modifier and Type | Class and Description |
---|---|
static class |
Initializer.InitializerConfig
Defines configuration values that are mapped via YAML code into this
class.
|
static interface |
Initializer.InputStreamLoader
We push the loading of resources to the application, just because in
some cases the application can offer the ability to load from the
classpath...
|
static class |
Initializer.PerforceOptions
Options to configure the seedPerforce method.
|
static class |
Initializer.SeedOptions |
Constructor and Description |
---|
Initializer(java.util.function.Supplier<com.perforce.p4java.server.IOptionsServer> serverSupplier) |
Modifier and Type | Method and Description |
---|---|
PerforceItemSet |
loadPerforceItems(Initializer.PerforceOptions options)
Load all json files under initializer/perforce/.json.
|
static void |
main(java.lang.String[] args)
Command line, which basically just takes a single configuration file
(because this is just that complicated).
|
void |
seedPerforce(Initializer.PerforceOptions options)
Seeds the perforce data as indicated by the JSON definitions provided
by the stream of "definitions" in the options.
|
public Initializer(java.util.function.Supplier<com.perforce.p4java.server.IOptionsServer> serverSupplier)
public void seedPerforce(Initializer.PerforceOptions options)
This will read all definitions, then initialize things in a "rational" order. The actual algorithm is somewhat tricky and dependent upon security settings.
In general, you should indicate definitions in the following order:
You can also indicate clients, if you want a few that "hang around" after initialization is complete.
The first user MUST be a superuser. That's the account we try to do most operations as. You also very likely do not want to perform changelist operations as the superuser, though you can, in case your usage is simple.
In changelist definitions, you can just use the client format convention "initializer-USER". We'll create that client for use of seeding data during this function call, and delete it before we're done.
options
- Options used to configure the function. Required if
you've got triggers and you want to customize the loaded
JSON files.java.lang.IllegalStateException
- if anything bad happens (do not catch,
this means you need to reconfigure your system)public PerforceItemSet loadPerforceItems(Initializer.PerforceOptions options)
java.lang.IllegalStateException
- When something bad happens; any error
resolution is simply going to require
system configurationpublic static void main(java.lang.String[] args)
args
- The command line strings, should really either be "-h" or
the path of a YAML configuration file.