Esempio n. 1
0
    def get_label(self, label_key, values_list_index):
        deployment = self.sm.get(Deployment, self._deployment_id)
        results = self.sm.list(DeploymentLabel,
                               include=['value'],
                               distinct=['value'],
                               filters={
                                   'key': label_key,
                                   '_labeled_model_fk': deployment._storage_id
                               },
                               get_all_results=True,
                               sort={
                                   'created_at': 'asc',
                                   'value': 'asc'
                               })
        label_values = [label.value for label in results]
        if not label_values:
            raise FunctionsEvaluationError(
                f'The deployment `{self._deployment_id}` does not have a '
                f'label with the key `{label_key}` assigned to it')
        if values_list_index is not None:
            if values_list_index > (len(label_values) - 1):
                raise FunctionsEvaluationError(
                    f'The provided label-values list index is out of range. '
                    f'The key `{label_key}` has {len(label_values)} values')
            return label_values[values_list_index]

        return label_values
Esempio n. 2
0
    def get_capability(capability_path):
        shared_dep_id, element_id = capability_path[0], capability_path[1]

        deployment = storage_manager.get(Deployment, shared_dep_id)
        capability = deployment.capabilities.get(element_id)

        if not capability:
            raise FunctionsEvaluationError(
                'Requested capability `{0}` is not declared '
                'in deployment `{1}`'.format(element_id, shared_dep_id))

        # We need to evaluate any potential intrinsic functions in the
        # capability's value in the context of the *shared* deployment,
        # instead of the current deployment, so we manually call the function
        capability = evaluate_intrinsic_functions(payload=capability,
                                                  deployment_id=shared_dep_id)

        # If it's a nested property of the capability
        if len(capability_path) > 2:
            try:
                capability = \
                    functions.get_nested_attribute_value_of_capability(
                        capability['value'],
                        capability_path)
            except parser_exceptions.FunctionEvaluationError as e:
                raise FunctionsEvaluationError(str(e))

        return capability['value']
Esempio n. 3
0
 def _get_capability_by_path(self, value, path):
     if len(path) <= 2:
         return value
     try:
         return functions.get_nested_attribute_value_of_capability(
             value, path)['value']
     except parser_exceptions.FunctionEvaluationError as e:
         raise FunctionsEvaluationError(str(e))
Esempio n. 4
0
def evaluate_intrinsic_functions(payload, deployment_id, context=None):
    context = context or {}
    sm = get_storage_manager()
    sm.get(Deployment, deployment_id, include=['id'])
    storage = FunctionEvaluationStorage(deployment_id, sm)

    try:
        return functions.evaluate_functions(payload, context, storage)
    except parser_exceptions.FunctionEvaluationError as e:
        raise FunctionsEvaluationError(str(e))
Esempio n. 5
0
def evaluate_node_instance(instance):
    deployment_id = instance['deployment_id']
    sm = get_storage_manager()
    sm.get(Deployment, deployment_id, include=['id'])
    storage = FunctionEvaluationStorage(deployment_id, sm)

    try:
        return functions.evaluate_node_instance_functions(instance, storage)
    except parser_exceptions.FunctionEvaluationError as e:
        raise FunctionsEvaluationError(str(e))
Esempio n. 6
0
def evaluate_node(node):
    # dsl-parser uses name in plans, while the db storage uses id :(
    node['name'] = node['id']
    deployment_id = node['deployment_id']
    sm = get_storage_manager()
    sm.get(Deployment, deployment_id, include=['id'])
    storage = FunctionEvaluationStorage(deployment_id, sm)
    try:
        return functions.evaluate_node_functions(node, storage)
    except parser_exceptions.FunctionEvaluationError as e:
        raise FunctionsEvaluationError(str(e))
Esempio n. 7
0
    def get_capability(self, capability_path):
        shared_dep_id, element_id = capability_path[0], capability_path[1]

        deployment = self.sm.get(Deployment, shared_dep_id)
        capability = deployment.capabilities.get(element_id)

        if not capability:
            raise FunctionsEvaluationError(
                'Requested capability `{0}` is not declared '
                'in deployment `{1}`'.format(element_id, shared_dep_id))

        # We need to evaluate any potential intrinsic functions in the
        # capability's value in the context of the *shared* deployment,
        # instead of the current deployment, so we manually call the function
        capability = evaluate_intrinsic_functions(
            payload=capability,
            deployment_id=shared_dep_id,
            context={EVAL_FUNCS_PATH_PREFIX_KEY: CAPABILITIES})['value']
        return self._get_capability_by_path(capability, capability_path)