MscmpSystInstance (mscmp_syst_instance v0.1.0)
API allowing for the management of application Instances.
"Instances" are instances of running application environments. Instances are established to host the application for different purposes, such as for running the application for production, training, and testing purposes; or as a means to implement multi-tenancy where each tenant application environment is an Instance.
Each Instance also requires supporting data in order to facilitate runtime actions, such as defining database roles with which to access database data. Such supporting information is also managed via this component.
Concepts
Instances are organized into a framework of other data types which allows us to better analyze and manage them and provides supplemental information required for Instance operation.
Datastores & Datastore Contexts
Each Instance is associated with a single Datastore. A Datastore is the database created to store the Instance's application data. Datastore Contexts are the database roles with which the Instance will access the database; this allows for application database connections secured to an appropriate range of actions and limited to an appropriate number of concurrent database connections. Or to put it another way, Datastore Contexts can be thought of as "Database Access Contexts".
Datastore and Datastore Context management is provided by the
MscmpSystDb component.
Owners
Owners represent the known tenants of the system. An Owner will own Instances of Applications. Owners have states which determine if they are active, not active, or even if they may be purged from the system.
Applications
Each Instance is an operational instance of a specific Application. An Application is simply what an end user would understand to be application: computer software which solves some problem for them better than could be solved without such software.
Applications in this component are added and maintained directly via database migrations therefore there is no API provided to manage applications and there are no user maintainable Application attributes.
Application Contexts
Application Context records define the expected Datastore Context records that must be created for each Instance. Each Application Context will be represent data ownership, data access restriction, and/or connection pool resource constraint. When created Instances will have its own database roles created for each of the defined Application Contexts.
Instance Types
Instance Type records are used to define the default resource utilization classes that are available for creating new Instances. These defaults include such starting values as the number of database connections to use for each Application Context and which server pools may host the Instance.
After Instance creation, the Instance Type serves no further role for the Instance.
Note that Instance Type records are a special case of the
Msdata.SystEnumItems record. The Enum Name for Instance Type
is, unsurprisingly, instance_types.
Instance Type Applications
Establishes that a given Instance Type will support a particular Application.
Instance Type Contexts
Defines defaults used in creating Instance Context records at Instance creation time.
When an association is made between an Instance Type and an Application via a Instance Type Application association, a new Instance Type Context record is created for the combination of the Instance Type and each of the Application's defined Application Contexts.
At Instance creation time, the Instance Type Context defaults are copied into Instance specific Instance Context records to define the actual database roles which the instance will use to interact with the database.
Note that Instance Type Context records are automatically created and destroyed via the creation of Instance Type Application records by way of database triggers; therefore the only application API related to these records is for updating them.
Instances
An Instance represents the single environment of a specific Application and a specific Owner. Instance records are used to know which database server to connect to, what Instance Context records are used for connecting to the database, and the current state of the Instance including whether or not it's been updated with the Application database definition, is in a usable state, or can be purged from the system.
Instance Contexts
An Instance's Instance Context records define specifically how an Instance will connect to its Datastore including such information as how many connections should be opened to the database.
Database triggers are responsible for creating and destroying Instance Context records. On creation, the Instance Context is created with default values defined by Instance Type Context records for the type of Instance being created. The default values set on Instance Context creation may be overridden via this API as desired.
Special Notes
This component requires that an instance of the MscmpSystEnums service has
been configured and started. Many of the API calls in this component will
fail if the MscmpSystEnums services are not available.
Summary
Owners
Creates a new Owner record.
Retrieves an Owner record by its internal name.
Retrieves the Owner record ID by Owner internal name.
Returns the Owner State Enumeration record for the given Internal Name argument.
Returns the Owner State Enumeration record which is configured as being default.
Tests to see if a specific Owner exists for the given Owner ID value.
Tests to see if a specific Owner exists for the given Owner Name value.
Tests to see if any Owner records exist in the database.
Removes an Owner record from the system.
Updates an Owner record.
Instance Types
Creates a new Instance Type record via the MscmpSystEnums service.
Creates an Instance Type/Application association.
Deletes an Instance Type from the MscmpSystEnums service.
Disassociates the Instance Type/Application support relationship.
Returns the Instance Type record for the given Internal Name; raises on error.
Returns the Instance Type record which is configured as the system default Instance Type.
Updates an existing Instance Type record via the MscmpSystEnums service.
Updates Instance Type Context default values which are applied to new Instance Contexts.
Instances
Creates a new Instance record.
Returns a Keyword List of the default values for each Instance Lifecycle State's functional type.
Returns the SystInstances record identified by its internal name.
Retrieves the Datastore Options based on the Instance database record and the provided Startup Options.
Returns the ID of the Instance record as identified by its internal name.
Retrieves the Instance State Enumeration record identified by the provided Internal Name.
Returns the Instance State Enumeration record which is configured as being default.
Initializes an uninitialized Instance.
Purges an eligible Instance from the system.
Sets the Instance Lifecycle State of an Instance.
Applications
Creates a new Application record.
Creates Application Context records for the identified Application.
Deletes an Application Context record from the system
Returns a populated Msdata.SystApplications struct for the requested record.
Retrieves the Application Context record ID for the record matching provided Internal Name argument.
Returns the Application record ID for the requested Application Internal Name; raises on error.
Returns a list of Application Context records.
Updates an existing Application record using the provided parameters as new values.
Updates an existing Application Context record.
Owners
@spec create_owner(MscmpSystInstance.Types.owner_params()) :: {:ok, Msdata.SystOwners.t()} | {:error, Mserror.InstanceError.t()}
Creates a new Owner record.
Parameters
owner_params- a map of Owner record attributes to use when creating a new record.internal_name- a predetermined unique identifier for the Owner record for use in programmatic contexts. This attribute is required and must be unique in the system.display_name- a unique, friendly name identifying the Owner and for use in user interfaces. This attribute is required and must be unique in the system.owner_state_id- the Owner State value with which to create the new Owner record. If not provided in the function call, this attribute will be defaulted to the configured Owner State default value for the enumeration.
@spec get_owner_by_name(MscmpSystInstance.Types.owner_name()) :: {:ok, Msdata.SystOwners.t()} | {:error, Mserror.InstanceError.t()}
Retrieves an Owner record by its internal name.
This retrieval operation will also populate the associated records of Owner State and the Owner State Functional Type.
Examples
iex> {:ok, %Msdata.SystOwners{internal_name: "owner1"}} = ...> MscmpSystInstance.get_owner_by_name("owner1")
@spec get_owner_id_by_name(MscmpSystInstance.Types.owner_name()) :: {:ok, MscmpSystInstance.Types.owner_id()} | {:error, Mserror.InstanceError.t()}
Retrieves the Owner record ID by Owner internal name.
Examples
iex> {:ok, owner_id} = MscmpSystInstance.get_owner_id_by_name("owner1") iex> is_binary(owner_id) true
@spec get_owner_state_by_name(MscmpSystInstance.Types.owner_state_name()) :: Msdata.SystEnumItems.t() | nil
Returns the Owner State Enumeration record for the given Internal Name argument.
If the requested Internal Name does not match an existing Owner State
Enumeration record nil is returned.
Parameters
owner_state_name- the internal name of the Owner State to retrieve.
Examples
Retrieving an Owner State Enumeration record.
iex> %Msdata.SystEnumItems{internal_name: "owner_states_sysdef_active"} =
...> MscmpSystInstance.get_owner_state_by_name("owner_states_sysdef_active")Trying to retrieve a non-existent Owner State.
iex> MscmpSystInstance.get_owner_state_by_name("nonexistent_state")
nil
@spec get_owner_state_default(MscmpSystInstance.Types.owner_state_func_types() | nil) :: Msdata.SystEnumItems.t()
Returns the Owner State Enumeration record which is configured as being default.
If no Owner State record is configured as default, then nil is returned.
Parameters
functional_type- an optional parameter which, if provided and notnil, will return the default Owner State record configured for the requested functional type rather than the system default Owner State. The default for this parameter is to treat the parameter as not provided (nil).
Examples
Requesting the system default Owner State.
iex> %Msdata.SystEnumItems{internal_name: "owner_states_sysdef_active"} =
...> MscmpSystInstance.get_owner_state_default()Requesting the default Owner State for a specific functional type.
iex> %Msdata.SystEnumItems{internal_name: "owner_states_sysdef_inactive"} =
...> MscmpSystInstance.get_owner_state_default(:owner_states_inactive)
@spec owner_id_exists?(MscmpSystInstance.Types.owner_id()) :: boolean()
Tests to see if a specific Owner exists for the given Owner ID value.
If the Owner record is found, the function returns true; otherwise false. Errors produce a result tuple.
Parameters
* `owner_id` - the record ID value of the Owner record to test for
existence.Examples
Check if a specific Owner record exists by ID.
iex> {:ok, owner_id} = MscmpSystInstance.get_owner_id_by_name("owner1")
iex> MscmpSystInstance.owner_id_exists?(owner_id)
trueIf a non-existent Owner is requested, the function indicates the record was not found by returning false.
iex> nonexistent_owner_id = Ecto.UUID.generate()
iex> MscmpSystInstance.owner_id_exists?(nonexistent_owner_id)
false
@spec owner_name_exists?(MscmpSystInstance.Types.owner_name()) :: boolean()
Tests to see if a specific Owner exists for the given Owner Name value.
The functions provide an existence test on an Owner record's Internal Name value.
If the Owner record is found, the function returns true; otherwise false. Errors produce a result tuple.
Examples
Check if a specific Owner record exists by name.
iex> MscmpSystInstance.owner_name_exists?("owner1")
trueIf a non-existent Owner is requested, the function indicates the record was not found.
iex> MscmpSystInstance.owner_name_exists?("nonexistent_owner")
false
@spec owners_exist?() :: boolean()
Tests to see if any Owner records exist in the database.
If Owner records are found, the function returns true; otherwise false. Errors produce a result tuple.
Examples
Check if any Owner record exists.
iex> MscmpSystInstance.owners_exist?()
true
@spec purge_owner(MscmpSystInstance.Types.owner_id() | Msdata.SystOwners.t()) :: :ok | {:error, Mserror.InstanceError.t()}
Removes an Owner record from the system.
Note that only Owner records in an Owner State of functional type
owner_states_purge_eligible may be purged from the system.
Parameters
owner- either the record ID of an Owner record to delete or theMsdata.SystOwnersstruct representing the Owner to purge.
@spec update_owner( MscmpSystInstance.Types.owner_id() | Msdata.SystOwners.t(), MscmpSystInstance.Types.owner_params() ) :: {:ok, Msdata.SystOwners.t()} | {:error, Mserror.InstanceError.t()}
Updates an Owner record.
Parameters
owner- This value must either by the record ID of an existing Owner record or theMsdata.SystOwnersstruct representing an existing owner.update_params- a map of Owner record attributes to be updated. For update operations only those attributes to be updates must be provided.internal_name- a predetermined unique identifier for the Owner record for use in programmatic contexts. This attribute must be unique in the system and may not be nil.display_name- a unique, friendly name identifying the owner and for use in user interfaces. This attribute must be unique in the system and may not be nil.owner_state_id- the record ID value of the new Owner State of the Owner record. Note that if this attribute is provided, but is set nil, an error will result.
Instance Types
@spec create_instance_type(MscmpSystInstance.Types.instance_type_params()) :: {:ok, Msdata.SystEnumItems.t()} | {:error, Mserror.InstanceError.t()}
Creates a new Instance Type record via the MscmpSystEnums service.
Parameters
instance_type_params- the parameters to use when creating the new Instance Type. The attributesinternal_name,display_name,external_name,user_description, anduser_optionsfields are required for Instance Type creation.
@spec create_instance_type_application( MscmpSystInstance.Types.instance_type_id(), MscmpSystInstance.Types.application_id() ) :: {:ok, Msdata.SystInstanceTypeApplications.t()} | {:error, Mserror.InstanceError.t()}
Creates an Instance Type/Application association.
Associating an Instance Type with an Application expresses that the Instance Type can support Instances of the given application.
Parameters
instance_type_id- the ID value of the Instance Type which will support Application Instances.application_id- the ID value which identifies the Application to be supported.
@spec delete_instance_type(MscmpSystInstance.Types.instance_type_name()) :: :ok | {:error, Mserror.InstanceError.t()}
Deletes an Instance Type from the MscmpSystEnums service.
Note that an attempt to delete an in-use Instance Type will result in a constraint error.
Parameters
instance_type_name- the internal name of an Instance Type to delete from the system.
@spec delete_instance_type_application( MscmpSystInstance.Types.instance_type_application_id() | Msdata.SystInstanceTypeApplications.t() ) :: :ok | {:error, Mserror.InstanceError.t()}
Disassociates the Instance Type/Application support relationship.
Note that this will only prevent the creation of new Instances of the Instance Type for the Application. Existing Instances that were created when the relationship was valid will continue to exist.
Parameters
instance_type_application- This value can be either the ID value of the Instance Type Application record or aMsdata.SystInstanceTypeApplicationsstruct with at least theidfield defined.
@spec get_instance_type_by_name(MscmpSystInstance.Types.instance_type_name()) :: Msdata.SystEnumItems.t() | nil
Returns the Instance Type record for the given Internal Name; raises on error.
On successful execution either the requested Instance Type Enumeration record
is returned or nil if the record does not exist.
Parameters
instance_type_name- the Internal Name of the desire Instance Type record to return.
Examples
Finding a Instance Type record by Internal Name.
iex> %Msdata.SystEnumItems{} =
...> MscmpSystInstance.get_instance_type_by_name("instance_types_big")Looking for a non-existent record.
iex> MscmpSystInstance.get_instance_type_by_name("nonexistent_type")
nil
@spec get_instance_type_default() :: Msdata.SystEnumItems.t()
Returns the Instance Type record which is configured as the system default Instance Type.
If no system default has not been defined nil is returned.
Examples
iex> %Msdata.SystEnumItems{} = MscmpSystInstance.get_instance_type_default()
@spec update_instance_type( MscmpSystInstance.Types.instance_type_name(), MscmpSystInstance.Types.instance_type_params() | %{} ) :: {:ok, Msdata.SystEnumItems.t()} | {:error, Mserror.InstanceError.t()}
Updates an existing Instance Type record via the MscmpSystEnums service.
Parameters
instance_type_name- the internal name of the Instance Type to target for updating.instance_type_params- the parameters to use when creating the new Instance Type. All attributes in the parameter map are optional in updating contexts.
@spec update_instance_type_context( MscmpSystInstance.Types.instance_type_context_id() | Msdata.SystInstanceTypeContexts.t(), MscmpSystInstance.Types.instance_type_context_params() | %{} ) :: {:ok, Msdata.SystInstanceTypeContexts.t()} | {:error, Mserror.InstanceError.t()}
Updates Instance Type Context default values which are applied to new Instance Contexts.
Parameters
instance_type_context- this value may either be the record ID of the target Instance Type Context record or a copy of the currentMsdata.SystInstanceTypeContextsstruct representing the target record.instance_type_context_params- a map containing those attributes to be updated with their new values.instance_type_id- the ID value of the owning Instance Type record. This value is required unless theinstance_type_nameattribute is provided.instance_type_name- the internal name value of the owning Instance Type record. This value required unless theinstance_type_idvalue is provided instead.application_context_id- the record ID value of the Application Context with which this record is associated. This value is required unless theapplication_context_namevalue is provided instead.application_context_name- the internal name value of the Application Context with which this record is associated. This value is required unless theapplication_context_idvalue is provided instead.default_db_pool_size- the default size of the database connection pool to use for Instances Contexts created for Instances of this Instance Type. This field defaults to 0 on Instance Type Context creation.
Instances
@spec create_instance(MscmpSystInstance.Types.instance_params()) :: {:ok, Msdata.SystInstances.t()} | {:error, Mserror.InstanceError.t()}
Creates a new Instance record.
Creating a new Instance record will also create new Instance Context records based on the defaults defined in the Instance Type Context records associated with the Instance Type and Application of the new Instance. This is accomplished with database triggers.
Parameters
instance_params- A map of attributes to use in creating the new Instance record in the system.internal_name- a pre-generated identifier for Instance record for use in programmatic contexts. This value is required and must be unique in the system.display_name- a friendly name which identifies the record for use in user interfaces. This value is required and must be unique in the system.dbserver_name- the name of the database server where the Instance Datastore exists. This value is required. Note that invalid values here may not be detected until such time as the Instance Datastore use is attempted.application_id- the record ID of the Application for which this Instance is being created. This value is required unless theapplication_nameattribute has been provided instead.application_name- the internal name of the Application for which this Instance is being created. This value is requires unless theapplication_idattribute has been provided instead.instance_code- A value used in constructing the Instance Context credentials. This value should be a randomly generated series of between 8 and 64 bytes.instance_type_id- the record ID of the Instance Type of the new Instance record. This attribute is required unless theinstance_type_nameattribute is provided instead.instance_type_name- the internal name of the Instance Type of the new Instance record. This attribute is requires unless theinstance_type_idattribute is provided instead.instance_lifecycle_state_id- the record ID of the Instance Lifecycle State in which to create the new Instance record. This value may be omitted and allowed to default based on the configured default Instance Lifecycle State. Optionally the Instance Lifecycle State may also be identified by theinstance_lifecycle_state_nameattribute.instance_lifecycle_state_name- the internal name of the Instance Lifecycle State in which to create the new Instance record. This value may be omitted and allowed to default based on the configured default Instance Lifecycle State. Optionally the Instance Lifecycle State may also be identified by theinstance_lifecycle_state_idattribute.owner_id- the record ID of the Owner of the Instance. This attribute is required unless theowner_nameattribute is provided.owner_name- th internal name of the Owner of the Instance. This attribute is required unless theowner_idattribute is provided.owning_instance_id- if the Instance is associated with a parent instance, such as a sandbox Instance being created for a parent production Instance, the parent/child relationship may be expressed by assigning this attribute to the record ID of the parent. This attribute is not required and the parent Instance may be identified by theowning_instance_nameattribute instead.owning_instance_name- an alternate identification method for identifying a parent Instance when creating a child Instance. This attribute is optional and may used in lieu of using theowning_instance_idattribute to establish the parent/child relationship of the new Instance.
@spec get_default_instance_lifecycle_state_ids() :: Keyword.t()
Returns a Keyword List of the default values for each Instance Lifecycle State's functional type.
Instance updating functions that change the Instance Lifecycle State value of the Instance will default to the appropriate Instance Lifecycle State if a specific Instance Lifecycle State value is not provided by the caller.
@spec get_instance_by_name(MscmpSystInstance.Types.instance_name()) :: {:ok, Msdata.SystInstances.t()} | {:error, Mserror.InstanceError.t()}
Returns the SystInstances record identified by its internal name.
Parameters
instance_name- the internal name of the Instance record to return.
Example
iex> {:ok, %Msdata.SystInstances{}} =
...> MscmpSystInstance.get_instance_by_name("app1_owner1_instance_types_sml")
@spec get_instance_datastore_options( MscmpSystInstance.Types.instance_id() | Msdata.SystInstances.t(), map() ) :: {:ok, MscmpSystDb.Types.DatastoreOptions.t()} | {:error, Mserror.InstanceError.t()}
Retrieves the Datastore Options based on the Instance database record and the provided Startup Options.
Parameters
instance- the instance parameter is either the record ID value of the Instance record desired or theMsdata.SystInstancesstruct for the target Instance.startup_options- a map of values containing the Startup Options obtained from theMscmpSystOptionscomponent.
@spec get_instance_id_by_name(MscmpSystInstance.Types.instance_name()) :: {:ok, MscmpSystInstance.Types.instance_id()} | {:error, Mserror.InstanceError.t()}
Returns the ID of the Instance record as identified by its internal name.
Parameters
instance_name- the internal name of the Instance record to reference.
Example
iex> {:ok, instance_id} =
...> MscmpSystInstance.get_instance_id_by_name("app1_owner1_instance_types_sml")
iex> is_binary(instance_id)
true
@spec get_instance_lifecycle_state_by_name( MscmpSystInstance.Types.instance_lifecycle_state_name() ) :: Msdata.SystEnumItems.t() | nil
Retrieves the Instance State Enumeration record identified by the provided Internal Name.
If the requested Internal Name does not match an existing Instance State
Enumeration record nil is returned.
Parameters
instance_lifecycle_state_name- the internal name of the Instance State to retrieve.
Examples
Retrieving an Instance State Enumeration record.
iex> %Msdata.SystEnumItems{internal_name: "instance_lifecycle_states_sysdef_active"} =
...> MscmpSystInstance.get_instance_lifecycle_state_by_name(
...> "instance_lifecycle_states_sysdef_active"
...> )Trying to retrieve a non-existent Instance State.
iex> MscmpSystInstance.get_instance_lifecycle_state_by_name("nonexistent_state")
nil
@spec get_instance_lifecycle_state_default( MscmpSystInstance.Types.instance_lifecycle_state_func_types() | nil ) :: Msdata.SystEnumItems.t()
Returns the Instance State Enumeration record which is configured as being default.
If no Instance State record is configured as default, then nil is returned.
Parameters
functional_type- an optional parameter which, if provided and notnil, will return the default Instance State record configured for the requested functional type rather than the system default Instance State. The default for this parameter is to treat the parameter as not provided (nil).
Examples
Requesting the system default Instance State.
iex> %Msdata.SystEnumItems{internal_name: "instance_lifecycle_states_sysdef_uninitialized"} =
...> MscmpSystInstance.get_instance_lifecycle_state_default()Requesting the default Instance State for a specific functional type.
iex> %Msdata.SystEnumItems{internal_name: "instance_lifecycle_states_sysdef_active"} =
...> MscmpSystInstance.get_instance_lifecycle_state_default(
...> :instance_lifecycle_states_active
...> )
@spec initialize_instance(MscmpSystInstance.Types.instance_id(), map(), Keyword.t()) :: {:ok, Msdata.SystInstances.t()} | {:error, Mserror.InstanceError.t()}
Initializes an uninitialized Instance.
When a new Instance is created in the database, the record is giving an
Instance Lifecycle State with a functional type of
instance_lifecycle_states_uninitialized meaning that the Instance record has
been created in the database, but the Instance's own database and associated
database roles have not yet been set up.
Initializing an Instance creates its database and its database roles
("Datastore" and "Datastore Contexts"). Once initialized, the Instance record
is given an Instance Lifecycle State of functional type
instance_lifecycle_states_initialized.
Initialized Instances may be started and have their Datastores migrated to the current version of the Instance's database.
Parameters
instance_id- the record ID of the Instance to initialize.startup_options- a map of values containing the Startup Options obtained from theMscmpSystOptionscomponent.opts- a Keyword List of optional values used during the initialization process. See the "Options" section for more.
Options
:db_shutdown_timeout(timeout/0) - Specifies the timeout value for the Datastore Context.
@spec purge_instance( MscmpSystInstance.Types.instance_id() | Msdata.SystInstances.t(), map() ) :: :ok | {:error, Mserror.InstanceError.t()}
Purges an eligible Instance from the system.
Purging an Instance drops its associated Datastore and its defining
Msdata.SystInstances records from the database.
In order for the purge to be successful, the Instance must be in an Instance
Lifecycle State of functional type instance_lifecycle_states_purge_eligible.
Warning
Naturally, great care must be taken in the lead up to calling this function as purging an Instance leads to the irreversible loss of the Instance's data (absent externally managed backups of some sort).
Parameters
instance- either the record ID or theMsdata.SystInstancesstruct of the Instance to purge.startup_options- a map of values containing the Startup Options obtained from theMscmpSystOptionscomponent.
@spec set_instance_lifecycle_state( Msdata.SystInstances.t(), MscmpSystInstance.Types.instance_lifecycle_state_id() ) :: {:ok, Msdata.SystInstances.t()} | {:error, Mserror.InstanceError.t()}
Sets the Instance Lifecycle State of an Instance.
Parameters
instance- the currentMsdata.SystInstancesstruct representing the Instance to be updated.instance_lifecycle_state_id- The record ID of the new Instance Lifecycle State value into which to place the Instance record.
Applications
@spec create_application(MscmpSystInstance.Types.application_params()) :: {:ok, Msdata.SystApplications.t()} | {:error, Mserror.InstanceError.t()}
Creates a new Application record.
Application Subsystems need means by which they can make the MscmpSystInstance component aware of their existence and this function provides the means by which to do that.
Note
Note that this function is meant to expose Application record management to the relevant Application Subsystem programs and is not intended for regular management activities by end users.
Parameters
application_params- the parameters with which the new Application record should be created. The following attribute values are available:internal_name- a predetermined unique identifier for the Application record for use in programmatic contexts. This attribute is required and must be unique in the system.display_name- a unique, friendly name identifying the Application and for use in user interfaces. This attribute is required and must be unique in the system.syst_description- a user facing description of the Application including any special usage requirements or preconditions. This attribute is required.
Examples
Creating a new Application record.
iex> new_app_params = %{
...> internal_name: "ex_app1",
...> display_name: "Example App 1",
...> syst_description: "An example application"
...> }
iex> {:ok, %Msdata.SystApplications{}} =
...> MscmpSystInstance.create_application(new_app_params)
@spec create_application_context(MscmpSystInstance.Types.application_context_params()) :: {:ok, Msdata.SystApplicationContexts.t()} | {:error, Mserror.InstanceError.t()}
Creates Application Context records for the identified Application.
Application Contexts describe the Datastore Contexts each Instance is expected
to support to allow an Application to access its data. Application Subsystems
use this function to create the any required Application Context records not
already registered in the MscmpSystInstance data. Application Contexts are
used in the creation of Msdata.SystInstanceContexts records and provide a
number of default values for the Instance Context records.
Note
Note that this function is meant to expose Application record management to the relevant Application Subsystem programs and is not intended for regular management activities by end users.
Parameters
application_context_params- a map defining the attributes which will be used to create the new Application Context record. The attributes are:internal_name- a predetermined unique identifier for the Application Context record for use in programmatic contexts. This attribute is required and must be unique in the system.display_name- a unique, friendly name identifying the Application Context and for use in user interfaces. This attribute is required and must be unique in the system.application_id- a reference to the ID value of the parent Application record. A valid value for this attribute is required unless theapplication_nameattribute is set with the Internal Name of an existing Application record. If both this attribute and theapplication_nameattributes are set, theattribute_namevalue will be used to resolve the parent Application.application_name- a reference to the Internal Name value of an existing Application record. This value is used to look-up theapplication_idand so if this attribute is provided with a valid value, theapplication_idattribute may be omitted. The value of this attribute takes precedence over any value set explicitly in theapplication_idattribute. Ifapplication_idis omitted, then this attribute is required.description- a description of the Application Context's role in the application and database. This becomes a comment in the database attached to the database role created for the context.start_context- a required boolean value which establishes the default value of derived Instance Context (Msdata.SystInstanceContexts)start_contextsettings. When true, an Instance Context record derived from this Application Context will be, by default, started as active database connections when the parent Instance is started. False indicates that by default Instance startup will not establish database connections for the context. This value muse be setfalsefor any Application Context defining a Datastore Owner Context or any other Context where thelogin_contextis setfalse.login_context- a required boolean value which indicates if a derived Instance Context is used to create database connections. If true, a derived Instance Context record will provide login information to establish a database connection on Instance start so long as itsstart_contextvalue is alsotrue. If this attribute is setfalsethe derived Instance Context record will not define a Context capable of logging into the database.database_owner_context- a required boolean value which, when true, is designates an Application Context record as establishing the default values for Instance Datastore/database owners. If true, thestart_contextandlogin_contextattributes must be set false as owner contexts are not used for database connectivity not may be started during the Instance start process.
Examples
Create an database owner Application Context record.
iex> new_context_params = %{
...> internal_name: "ex_app2_owner",
...> display_name: "Example App 2 Owner",
...> application_name: "ex_app2",
...> description: "Database role owning objects for 'ex_app2'.",
...> start_context: false,
...> login_context: false,
...> database_owner_context: true
...> }
iex> {:ok, %Msdata.SystApplicationContexts{}} =
...> MscmpSystInstance.create_application_context(new_context_params)
@spec delete_application_context(MscmpSystInstance.Types.application_context_id()) :: :ok | {:error, Mserror.InstanceError.t()}
Deletes an Application Context record from the system
Application Subsystems may use this function to remove an obsolete Application Context record from the system.
Note
Note that this function is meant to expose Application record management to the relevant Application Subsystem programs and is not intended for regular management activities by end users.
Warning!
While this function will remove an Application Context record from the system and prevent any new Instances of the Application from including the deleted Context, existing Instance Contexts based on the Application Context are not currently cleaned up by this function. Any clean-up of existing Instance Context data and of associated database roles and verification of extended clean-up activities is therefore the responsibility of the caller.
On successful delete of the record, a value of :ok is returned. If the
record is not found or other errors occur, an error tuple is returned.
Parameters
application_context_id- the record ID of the Application Context record to delete. This value is required.
Examples
Deleting an existing Application Context.
iex> record_id = MscmpSystInstance.get_application_context_id_by_name("ex_app2_delctx")
iex> MscmpSystInstance.delete_application_context(record_id)
:okAttempting to delete a non-existent record.
iex> record_id = "00000000-0000-0000-0000-000000000000"
iex> {:error, result} = MscmpSystInstance.delete_application_context(record_id)
iex> %Mserror.InstanceError{kind: :application_data, cause: example_cause} = result
iex> example_cause
{:error, {:not_found, "00000000-0000-0000-0000-000000000000"}}
@spec get_application( MscmpSystInstance.Types.application_id() | MscmpSystInstance.Types.application_name(), Keyword.t() ) :: Msdata.SystApplications.t() | nil
Returns a populated Msdata.SystApplications struct for the requested record.
Parameters
application- either the record ID of the desired Application record or its Internal Name. This parameter is required.opts- allows optional parameters to be provided which govern the behavior of this function.
Options
:include_contexts(boolean/0) - When true, indicates that application context records should be preloaded. The default value isfalse.
@spec get_application_context_id_by_name( MscmpSystInstance.Types.application_context_name() ) :: MscmpSystInstance.Types.application_context_id() | nil
Retrieves the Application Context record ID for the record matching provided Internal Name argument.
When the requested Application Context record can not be found this function
returns nil. All errors raise an exception.
Parameters
application_context_name- the Internal Name value of the Application Context record to search for.
Examples
Finding an existing Application Context.
iex> id = MscmpSystInstance.get_application_context_id_by_name("ex_app2_idctx")
iex> is_binary(id)
trueSearching for a non-existent Application Context.
iex> MscmpSystInstance.get_application_context_id_by_name("nonexistent_context")
nil
@spec get_application_id_by_name(MscmpSystInstance.Types.application_name()) :: MscmpSystInstance.Types.application_id() | nil
Returns the Application record ID for the requested Application Internal Name; raises on error.
On successful execution the record ID of the requested Application is
returned. If the requested Application Internal Name is not found nil is
returned.
Note
Note that this function is meant to expose Application record management to the relevant Application Subsystem programs and is not intended for regular management activities by end users.
Parameters
application_name- the internal name of the desired Application record.
Examples
Finding an application returns its ID value.
iex> application_id = MscmpSystInstance.get_application_id_by_name("app1")
iex> is_binary(application_id)
true Asking for a non-existent application returns nil.
iex> MscmpSystInstance.get_application_id_by_name("nonexistent_application")
nil
@spec list_application_contexts(MscmpSystInstance.Types.application_id() | nil) :: {:ok, [Msdata.SystApplicationContexts.t()]} | {:error, Mserror.InstanceError.t()}
Returns a list of Application Context records.
Parameters
application_id- an optional reference to a specific application for which to return Application Context records. By default this value isnilwhich results in all Application Context records for all Applications being returned.
@spec update_application( MscmpSystInstance.Types.application_id() | Msdata.SystApplications.t(), MscmpSystInstance.Types.application_params() ) :: {:ok, Msdata.SystApplications.t()} | {:error, Mserror.InstanceError.t()}
Updates an existing Application record using the provided parameters as new values.
Allows an Application Subsystem program to update its representative Application record as required.
Note
Note that this function is meant to expose Application record management to the relevant Application Subsystem programs and is not intended for regular management activities by end users.
Parameters
application- either a fully populatedMsdata.SystApplicationsstruct representing the current state of the Application record or the ID of the Application record to update. This argument is required.application_params- a map containing the attributes with updated values for the Application record update operation. The attributes which may be updated are:display_name- a unique, friendly name identifying the Application and for use in user interfaces. This value may not be setnilif it is included.syst_description- a user facing description of the Application including any special usage requirements or preconditions. This attribute may not be setnilif it is included.
Examples
Creating a new Application record.
iex> target_app_id = MscmpSystInstance.get_application_id_by_name("ex_app2")
iex> update_app_params = %{
...> display_name: "Example App #2",
...> syst_description: "An updated example application."
...> }
iex> {:ok, %Msdata.SystApplications{display_name: "Example App #2"}} =
...> MscmpSystInstance.update_application(target_app_id, update_app_params)
@spec update_application_context( MscmpSystInstance.Types.application_context_id() | Msdata.SystApplicationContexts.t(), MscmpSystInstance.Types.application_context_params() ) :: {:ok, Msdata.SystApplicationContexts.t()} | {:error, Mserror.InstanceError.t()}
Updates an existing Application Context record.
Allows an Application Subsystem to update its Application Context entries as permitted.
Note
Note that this function is meant to expose Application record management to the relevant Application Subsystem programs and is not intended for regular management activities by end users.
Parameters
application_context- this required parameter may either be the Application Context record ID or the fully populatedMsdata.SystApplicationContextsstruct to update.application_context_params- a map of attributes which are to be updated with the new values of those attributes. The available attributes for updates are:display_name- a unique, friendly name identifying the Application Context and for use in user interfaces. This attribute is required and must be unique in the system.description- a description of the Application Context's role in the application and database. This becomes a comment in the database attached to the database role created for the context.start_context- a required boolean value which establishes the default value of derived Instance Context (Msdata.SystInstanceContexts)start_contextsettings. When true, an Instance Context record derived from this Application Context will be, by default, started as active database connections when the parent Instance is started. False indicates that by default Instance startup will not establish database connections for the context. This value muse be setfalsefor any Application Context defining a Datastore Owner Context or any other Context where thelogin_contextis setfalse.
Examples
Updating an existing Application Context record
iex> app_context_id =
...> MscmpSystInstance.get_application_context_id_by_name("ex_app2_updctx")
iex> update_params = %{
...> display_name: "Updated Ex. App 2 Context",
...> description: "A now updated description",
...> start_context: false
...> }
iex> {:ok,
...> %Msdata.SystApplicationContexts{
...> display_name: "Updated Ex. App 2 Context",
...> description: "A now updated description",
...> start_context: false
...> }} =
...> MscmpSystInstance.update_application_context(app_context_id, update_params)