def is_loaded(self, application_id: str = None, application_name: str = None) -> bool: """Check if application is loaded, by passing application ID or name, returns True or False. Args: application_id: Application ID application_name: Application name """ if application_id is None and application_name is None: helper.exception_handler( "Please specify either 'application_name' or 'application_id' argument.") if application_id is None: app_list = Application._list_application_ids(self.connection, name=application_name) if app_list: application_id = app_list[0] else: msg = f"There is no application with the given name: '{application_name}'" raise ValueError(msg) nodes = self.list_nodes(application_id=application_id) loaded = False for node in nodes: status = node['projects'][0]['status'] loaded = True if status == 'loaded' else False if loaded: break return loaded
def create_application(self, name: str, description: str = None, force: bool = False) -> Optional["Application"]: """Create a new application on the envrionment. Args: name: Name of Application. description: Description of Aplication. force: If `True`, overrides the prompt. """ return Application._create(self.connection, name, description, force)
def load_application(self, application_name: str, on_nodes: Union[str, List[str]] = None) -> None: """Request to load the application onto the chosen cluster nodes. If nodes are not specified, the application will be loaded on all nodes. Args: application_name: name of application which will be loaded on_nodes: name of node or nodes, if not passed, application will be loaded on all of the nodes """ from mstrio.server.application import Application app = Application._list_applications(self.connection, name=application_name)[0] app.load(on_nodes=on_nodes)
def list_loaded_applications(self, to_dictionary: bool = False, **filters) -> Union[List["Application"], List[dict]]: """Return list of all loaded application objects or application dicts if `to_dictionary=True` that the user has access to. Optionally filter the Applications by specifying the `filters` keyword arguments. Args: to_dictionary: If True, returns list of application dicts **filters: Available filter parameters: ['acg', 'id', 'name', 'status', 'alias', 'description', 'date_created', 'date_modified', 'owner'] """ return Application._list_loaded_applications( connection=self.connection, to_dictionary=to_dictionary, **filters, )
def unload_application(self, application_name: str, on_nodes: Union[str, List[str]] = None) -> None: """Request to unload the application from the chosen cluster nodes. If nodes are not specified, the application will be unloaded on all nodes. The unload action cannot be performed until all jobs and connections for application are completed. Once these processes have finished, pending application will be automatically unloaded. Args: application_name: name of application which will be unloaded on_nodes: name of node or nodes, if not passed, application will be unloaded on all of the nodes """ from mstrio.server.application import Application app = Application._list_applications(self.connection, name=application_name)[0] app.unload(on_nodes=on_nodes)
def list_applications(self, to_dictionary: bool = False, limit: int = None, **filters) -> Union[List["Application"], List[dict]]: """Return list of application objects or application dicts if `to_dictionary=True`. Optionally filter the Applications by specifying the `filters` keyword arguments. Args: to_dictionary: If True returns list of application dicts. limit: limit the number of elements returned. If `None`, all objects are returned. **filters: Available filter parameters: ['name', 'id', 'description', 'date_created', 'date_modified', 'owner']. """ return Application._list_applications( connection=self.connection, to_dictionary=to_dictionary, limit=limit, **filters, )
def _app_id_check(connection, application_id, application_name): """Check if the application name exists and returns the application ID. Args: connection(object): MicroStrategy connection object application_id: Application ID application_name: Application name """ if application_id is None and application_name is None: msg = ("Please specify either 'application_name' or 'application_id' " "parameter in the constructor.") helper.exception_handler(msg) if application_id is None: app_loaded_list = Application._list_loaded_applications(connection, to_dictionary=True, name=application_name) try: application_id = app_loaded_list[0]['id'] except IndexError: helper.exception_handler( "There is no application with the given name: '{}'".format(application_name), exception_type=ValueError) return application_id
def revoke_from(self, members: Union[List[str], List["User"], List["UserGroup"]], application: Union["Application", str]) -> None: """Remove users/user groups from a Security Role. Args: members(list): List of objects or IDs of Users or User Groups which will be removed from this Security Role. application(Application, str): Application object or name to which this removal will apply. """ from mstrio.server.application import Application from mstrio.users_and_groups.user import User from mstrio.users_and_groups.user_group import UserGroup if isinstance(application, Application): application_id = application.id application_name = application.name elif isinstance(application, str): application_list = Application._list_applications( connection=self.connection, to_dictionary=True, name=application) if application_list: application_id = application_list[0]['id'] application_name = application_list[0]['name'] else: helper.exception_handler( "Application name '{}' does not exist.".format( application)) else: helper.exception_handler( "Application parameter must be of type str or Application.", TypeError) # create list of objects from strings/objects/lists members_list = members if isinstance(members, list) else [members] members_list = [ obj.id if isinstance(obj, (User, UserGroup)) else str(obj) for obj in members_list ] existing_ids = [ obj['id'] for obj in self.list_members(application_name=application_name) ] succeeded = list(set(members_list).intersection(set(existing_ids))) failed = list(set(members_list) - set(succeeded)) value = {"projectId": application_id, "memberIds": members_list} self._update_nested_properties( objects=value, path="members", op='remove', ) if succeeded: if config.verbose: print("Revoked Security Role '{}' from {}".format( self.name, succeeded)) if failed and config.verbose: print("Security Role '{}' does not have member(s) {}".format( self.name, failed))
base_url = "https://<>/MicroStrategyLibrary/api" username = "******" password = "******" conn = Connection(base_url, username, password, application_name="MicroStrategy Tutorial", login_mode=1) env = Environment(connection=conn) # get list of all applications or those just loaded all_applications = env.list_applications() loaded_applications = env.list_loaded_applications() # get application with a given name app = Application(connection=conn, name="MicroStrategy Tutorial") # idle/resume an application on a given node(s) (name(s) of existing node(s) # should be used) app.idle(on_nodes=["node1"]) app.resume(on_nodes="node1") # unload/load an application from/to a given node(s) (name(s) of existing # node(s) should be used) app.unload(on_nodes="node1") app.load(on_nodes="node1") # get settings of an application as a dataframe app_settings_df = app.settings.to_dataframe # create an application and store it in variable to have immediate access to it new_app = env.create_application(name="Demo Application 1", description="some description")
# stop/start service on selected nodes (error will be thrown in case of wrong # names of service or nodes) clstr.stop(service='Apache-Kafka', nodes=['env-xxxxxxlaio1use1', 'env-xxxxxxlaio2use1']) clstr.start(service='Apache-Kafka', nodes=['env-xxxxxxlaio1use1', 'env-xxxxxxlaio2use1']) env = Environment(connection=conn) # list all applications available for the given connection (it is possible via # class Cluster or Environment) apps = env.list_applications() apps = clstr.list_applications() # load or unload chosen application (it is possible via class Cluster or # Application) app = Application(connection=conn, name='MicroStrategy Tutorial') app.load() app.unload() # via Cluster can we also specify on which node(s) application will be loaded # or unloaded clstr.load_application(application_name='MicroStrategy Tutorial', on_nodes=['env-xxxxxxlaio1use1', 'env-xxxxxxlaio2use1']) clstr.unload_application( application_name='MicroStrategy Tutorial', on_nodes=['env-xxxxxxlaio1use1', 'env-xxxxxxlaio2use1']) # get settings of a server as a dataframe server_settings_df = env.server_settings.to_dataframe # save/load settings of a server to/from a file (format can be 'csv', 'json' or