Admin

Bases: Consolidater

Source code in geocube/admin.py
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
class Admin(Consolidater):
    def __init__(self, uri: str, secure: bool = False, api_key: str = "", verbose: bool = True):
        """
        Initialise the connexion to the Geocube Server

        Args:
            uri: of the Geocube Server
            secure: True to use a TLS Connexion
            api_key: (optional) API Key if Geocube Server is secured using a bearer authentication
            verbose: display the version of the Geocube Server
        """
        super().__init__(uri, secure, api_key, verbose)
        self.admin_stub = admin_pb2_grpc.AdminStub(self._channel)

    @utils.catch_rpc_error
    def admin_tidy(self, aois: bool = False, records: bool = False, variables: bool = False, instances: bool = False,
                   containers: bool = False, consolidation_params: bool = False, simulate: bool = True):
        """
        Admin function to tidy the Geocube Database.
        Remove all the entities that are not linked to any dataset.
        Should be used with caution when no ingestion or indexation task is in progress.

        Args:
            aois: remove the pending AOI
            records: remove the pending Records
            variables: remove the pending Variables
            instances: remove the pending Instances
            containers: remove the pending Containers
            consolidation_params: remove the pending ConsolidationParams
            simulate: if True no operation is performed. Only the number of entities that would have been deleted
        """
        res = self.admin_stub.TidyDB(admin_pb2.TidyDBRequest(
            PendingAOIs=aois, PendingRecords=records, PendingVariables=variables, PendingInstances=instances,
            PendingContainers=containers, PendingParams=consolidation_params, Simulate=simulate
        ))
        if simulate:
            print("Simulation:")

        print("{} aois deleted\n"
              "{} records deleted\n"
              "{} variables deleted\n"
              "{} instances deleted\n"
              "{} containers deleted\n"
              .format(res.NbAOIs, res.NbRecords, res.NbVariables, res.NbInstances, res.NbContainers))

    @utils.catch_rpc_error
    def admin_update_datasets(self, instance: Union[str, entities.VariableInstance],
                              records: List[Union[str, entities.Record]],
                              dformat: Union[Dict, Tuple, str], min_out: float, max_out: float,
                              exponent: float, simulate: bool):
        """
        Admin function to update some sensitive information of datasets referenced by an instance and a list of records

        Args:
            instance: select the datasets that are referenced by this instance
            records: select the datasets that are referenced by these records
            dformat: new dataformat
            min_out: new min_out
            max_out: new max_out
            exponent: new exponent
            simulate: if True, no operation is performed. Only display the datasets that would have been updated.
        """
        res = self.admin_stub.UpdateDatasets(admin_pb2.UpdateDatasetsRequest(
            simulate=simulate, instance_id=entities.get_id(instance),
            record_ids=entities.get_ids(records),
            dformat=entities.DataFormat.from_user(dformat).to_pb(),
            real_min_value=min_out, real_max_value=max_out, exponent=exponent))
        if simulate:
            print("Simulation:")

        for r, count in res.results.items():
            print("{} : {}\n".format(r, count))

    @utils.catch_rpc_error
    def admin_delete_datasets(self, instances: List[Union[str, entities.VariableInstance]],
                              records: List[Union[str, entities.Record]],
                              file_patterns: List[str] = None,
                              execution_level: entities.ExecutionLevel = entities.ExecutionLevel.STEP_BY_STEP_CRITICAL,
                              job_name: str = None) -> entities.Job:
        """
        Admin function to delete datasets that are referenced by a list of instances and a list of records.
        This function is provided without any guaranties of service continuity.
        In the future, a secured function will be provided to safely delete datasets.

        Args:
            instances: select all the datasets referenced by these instances.
            records: select all the datasets referenced by these records.
            file_patterns: select all the datasets with on of the given file patterns
                (support * and ? for all or any characters and trailing (?i) for case-insensitiveness)
            execution_level: see entities.ExecutionLevel.
            job_name: [optional] gives a name to the job, otherwise, a name will be automatically generated
        """
        res = self.admin_stub.DeleteDatasets(admin_pb2.DeleteDatasetsRequest(
            job_name=job_name if job_name is not None else f"Deletion_{datetime.now()}_{len(records)}_records",
            execution_level=execution_level.value,
            instance_ids=entities.get_ids(instances), record_ids=entities.get_ids(records),
            dataset_patterns=file_patterns)
        )

        return entities.Job.from_pb(self.stub, res.job)

__init__(uri, secure=False, api_key='', verbose=True)

Initialise the connexion to the Geocube Server

Parameters:

Name Type Description Default
uri str

of the Geocube Server

required
secure bool

True to use a TLS Connexion

False
api_key str

(optional) API Key if Geocube Server is secured using a bearer authentication

''
verbose bool

display the version of the Geocube Server

True
Source code in geocube/admin.py
 9
10
11
12
13
14
15
16
17
18
19
20
def __init__(self, uri: str, secure: bool = False, api_key: str = "", verbose: bool = True):
    """
    Initialise the connexion to the Geocube Server

    Args:
        uri: of the Geocube Server
        secure: True to use a TLS Connexion
        api_key: (optional) API Key if Geocube Server is secured using a bearer authentication
        verbose: display the version of the Geocube Server
    """
    super().__init__(uri, secure, api_key, verbose)
    self.admin_stub = admin_pb2_grpc.AdminStub(self._channel)

admin_delete_datasets(instances, records, file_patterns=None, execution_level=entities.ExecutionLevel.STEP_BY_STEP_CRITICAL, job_name=None)

Admin function to delete datasets that are referenced by a list of instances and a list of records. This function is provided without any guaranties of service continuity. In the future, a secured function will be provided to safely delete datasets.

Parameters:

Name Type Description Default
instances List[Union[str, entities.VariableInstance]]

select all the datasets referenced by these instances.

required
records List[Union[str, entities.Record]]

select all the datasets referenced by these records.

required
file_patterns List[str]

select all the datasets with on of the given file patterns (support * and ? for all or any characters and trailing (?i) for case-insensitiveness)

None
execution_level entities.ExecutionLevel

see entities.ExecutionLevel.

entities.ExecutionLevel.STEP_BY_STEP_CRITICAL
job_name str

[optional] gives a name to the job, otherwise, a name will be automatically generated

None
Source code in geocube/admin.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
@utils.catch_rpc_error
def admin_delete_datasets(self, instances: List[Union[str, entities.VariableInstance]],
                          records: List[Union[str, entities.Record]],
                          file_patterns: List[str] = None,
                          execution_level: entities.ExecutionLevel = entities.ExecutionLevel.STEP_BY_STEP_CRITICAL,
                          job_name: str = None) -> entities.Job:
    """
    Admin function to delete datasets that are referenced by a list of instances and a list of records.
    This function is provided without any guaranties of service continuity.
    In the future, a secured function will be provided to safely delete datasets.

    Args:
        instances: select all the datasets referenced by these instances.
        records: select all the datasets referenced by these records.
        file_patterns: select all the datasets with on of the given file patterns
            (support * and ? for all or any characters and trailing (?i) for case-insensitiveness)
        execution_level: see entities.ExecutionLevel.
        job_name: [optional] gives a name to the job, otherwise, a name will be automatically generated
    """
    res = self.admin_stub.DeleteDatasets(admin_pb2.DeleteDatasetsRequest(
        job_name=job_name if job_name is not None else f"Deletion_{datetime.now()}_{len(records)}_records",
        execution_level=execution_level.value,
        instance_ids=entities.get_ids(instances), record_ids=entities.get_ids(records),
        dataset_patterns=file_patterns)
    )

    return entities.Job.from_pb(self.stub, res.job)

admin_tidy(aois=False, records=False, variables=False, instances=False, containers=False, consolidation_params=False, simulate=True)

Admin function to tidy the Geocube Database. Remove all the entities that are not linked to any dataset. Should be used with caution when no ingestion or indexation task is in progress.

Parameters:

Name Type Description Default
aois bool

remove the pending AOI

False
records bool

remove the pending Records

False
variables bool

remove the pending Variables

False
instances bool

remove the pending Instances

False
containers bool

remove the pending Containers

False
consolidation_params bool

remove the pending ConsolidationParams

False
simulate bool

if True no operation is performed. Only the number of entities that would have been deleted

True
Source code in geocube/admin.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@utils.catch_rpc_error
def admin_tidy(self, aois: bool = False, records: bool = False, variables: bool = False, instances: bool = False,
               containers: bool = False, consolidation_params: bool = False, simulate: bool = True):
    """
    Admin function to tidy the Geocube Database.
    Remove all the entities that are not linked to any dataset.
    Should be used with caution when no ingestion or indexation task is in progress.

    Args:
        aois: remove the pending AOI
        records: remove the pending Records
        variables: remove the pending Variables
        instances: remove the pending Instances
        containers: remove the pending Containers
        consolidation_params: remove the pending ConsolidationParams
        simulate: if True no operation is performed. Only the number of entities that would have been deleted
    """
    res = self.admin_stub.TidyDB(admin_pb2.TidyDBRequest(
        PendingAOIs=aois, PendingRecords=records, PendingVariables=variables, PendingInstances=instances,
        PendingContainers=containers, PendingParams=consolidation_params, Simulate=simulate
    ))
    if simulate:
        print("Simulation:")

    print("{} aois deleted\n"
          "{} records deleted\n"
          "{} variables deleted\n"
          "{} instances deleted\n"
          "{} containers deleted\n"
          .format(res.NbAOIs, res.NbRecords, res.NbVariables, res.NbInstances, res.NbContainers))

admin_update_datasets(instance, records, dformat, min_out, max_out, exponent, simulate)

Admin function to update some sensitive information of datasets referenced by an instance and a list of records

Parameters:

Name Type Description Default
instance Union[str, entities.VariableInstance]

select the datasets that are referenced by this instance

required
records List[Union[str, entities.Record]]

select the datasets that are referenced by these records

required
dformat Union[Dict, Tuple, str]

new dataformat

required
min_out float

new min_out

required
max_out float

new max_out

required
exponent float

new exponent

required
simulate bool

if True, no operation is performed. Only display the datasets that would have been updated.

required
Source code in geocube/admin.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@utils.catch_rpc_error
def admin_update_datasets(self, instance: Union[str, entities.VariableInstance],
                          records: List[Union[str, entities.Record]],
                          dformat: Union[Dict, Tuple, str], min_out: float, max_out: float,
                          exponent: float, simulate: bool):
    """
    Admin function to update some sensitive information of datasets referenced by an instance and a list of records

    Args:
        instance: select the datasets that are referenced by this instance
        records: select the datasets that are referenced by these records
        dformat: new dataformat
        min_out: new min_out
        max_out: new max_out
        exponent: new exponent
        simulate: if True, no operation is performed. Only display the datasets that would have been updated.
    """
    res = self.admin_stub.UpdateDatasets(admin_pb2.UpdateDatasetsRequest(
        simulate=simulate, instance_id=entities.get_id(instance),
        record_ids=entities.get_ids(records),
        dformat=entities.DataFormat.from_user(dformat).to_pb(),
        real_min_value=min_out, real_max_value=max_out, exponent=exponent))
    if simulate:
        print("Simulation:")

    for r, count in res.results.items():
        print("{} : {}\n".format(r, count))