Example #1
0
def _update_database_parameters(request_post, database):
    from physical.models import DatabaseInfraParameter
    from physical.models import Parameter
    changed_parameters = []
    for key in request_post.keys():
        if key.startswith("new_value_"):
            parameter_new_value = request_post.get(key)
            if parameter_new_value:
                parameter_id = key.split("new_value_")[1]
                parameter = Parameter.objects.get(id=parameter_id)
                changed = DatabaseInfraParameter.update_parameter_value(
                    databaseinfra=database.databaseinfra,
                    parameter=parameter,
                    value=parameter_new_value,
                )
                if changed:
                    changed_parameters.append(parameter_id)

        if key.startswith("checkbox_reset_"):
            reset_default_value = request_post.get(key)
            if reset_default_value == "on":
                parameter_id = key.split("checkbox_reset_")[1]
                parameter = Parameter.objects.get(id=parameter_id)
                changed = DatabaseInfraParameter.set_reset_default(
                    databaseinfra=database.databaseinfra,
                    parameter=parameter,
                )
                if changed:
                    changed_parameters.append(parameter_id)

    return changed_parameters
    def update_database_parameters(request_post, database):
        from physical.models import DatabaseInfraParameter
        from physical.models import Parameter

        error = False

        for key in request_post.keys():
            if key.startswith("new_value_"):
                parameter_new_value = request_post.get(key)
                if parameter_new_value:
                    parameter_id = key.split("new_value_")[1]
                    parameter = Parameter.objects.get(id=parameter_id)
                    if not ParameterValidator.validate_value(
                            parameter_new_value, parameter):
                        error = "Invalid Parameter Value for {}".format(
                            parameter.name)
                        return None, error

        changed_parameters = []
        for key in request_post.keys():
            if key.startswith("new_value_"):
                parameter_new_value = request_post.get(key)
                if parameter_new_value:
                    parameter_id = key.split("new_value_")[1]
                    parameter = Parameter.objects.get(id=parameter_id)
                    changed = DatabaseInfraParameter.update_parameter_value(
                        databaseinfra=database.databaseinfra,
                        parameter=parameter,
                        value=parameter_new_value,
                    )
                    if changed:
                        changed_parameters.append(parameter_id)

            if key.startswith("checkbox_reset_"):
                reset_default_value = request_post.get(key)
                if reset_default_value == "on":
                    parameter_id = key.split("checkbox_reset_")[1]
                    parameter = Parameter.objects.get(id=parameter_id)
                    changed = DatabaseInfraParameter.set_reset_default(
                        databaseinfra=database.databaseinfra,
                        parameter=parameter,
                    )
                    if changed:
                        changed_parameters.append(parameter_id)

        return changed_parameters, error
Example #3
0
    def update_database_parameters(request_post, database):
        from physical.models import DatabaseInfraParameter
        from physical.models import Parameter

        error = False

        for key in request_post.keys():
            if key.startswith("new_value_"):
                parameter_new_value = request_post.get(key)
                if parameter_new_value:
                    parameter_id = key.split("new_value_")[1]
                    parameter = Parameter.objects.get(id=parameter_id)
                    if not ParameterValidator.validate_value(parameter_new_value, parameter):
                        error = "Invalid Parameter Value for {}".format(parameter.name)
                        return None, error

        changed_parameters = []
        for key in request_post.keys():
            if key.startswith("new_value_"):
                parameter_new_value = request_post.get(key)
                if parameter_new_value:
                    parameter_id = key.split("new_value_")[1]
                    parameter = Parameter.objects.get(id=parameter_id)
                    changed = DatabaseInfraParameter.update_parameter_value(
                        databaseinfra=database.databaseinfra,
                        parameter=parameter,
                        value=parameter_new_value,
                    )
                    if changed:
                        changed_parameters.append(parameter_id)

            if key.startswith("checkbox_reset_"):
                reset_default_value = request_post.get(key)
                if reset_default_value == "on":
                    parameter_id = key.split("checkbox_reset_")[1]
                    parameter = Parameter.objects.get(id=parameter_id)
                    changed = DatabaseInfraParameter.set_reset_default(
                        databaseinfra=database.databaseinfra,
                        parameter=parameter,
                    )
                    if changed:
                        changed_parameters.append(parameter_id)

        return changed_parameters, error
Example #4
0
def change_parameters_database(self, database, user, task, since_step=0):
    worker_name = get_worker_name()
    task = TaskHistory.register(self.request, user, task, worker_name)

    infra = database.infra
    plan = infra.plan
    class_path = plan.replication_topology.class_path

    from physical.models import DatabaseInfraParameter
    changed_parameters = DatabaseInfraParameter.get_databaseinfra_changed_parameters(
        databaseinfra=infra,
    )
    all_dinamic = True
    custom_procedure = None
    for changed_parameter in changed_parameters:
        if changed_parameter.parameter.dynamic is False:
            all_dinamic = False
            break
    for changed_parameter in changed_parameters:
        if changed_parameter.parameter.custom_method:
            custom_procedure = changed_parameter.parameter.custom_method
            break

    steps = get_database_change_parameter_setting(
        class_path, all_dinamic, custom_procedure)

    LOG.info(steps)

    task.add_detail("Changed parameters:", level=0)
    for changed_parameter in changed_parameters:
        msg = "{}: old value: [{}], new value: [{}]".format(
            changed_parameter.parameter.name,
            changed_parameter.current_value,
            changed_parameter.value

        )
        task.add_detail(msg, level=1)
    task.add_detail("", level=0)

    if since_step > 0:
        steps_dec = get_database_change_parameter_retry_steps_count(
            class_path, all_dinamic, custom_procedure)
        LOG.info('since_step: {}, steps_dec: {}'.format(since_step, steps_dec))
        since_step = since_step - steps_dec
        if since_step < 0:
            since_step = 0

    database_change_parameter = DatabaseChangeParameter()
    database_change_parameter.database = database
    database_change_parameter.task = task
    database_change_parameter.save()

    instances_to_change_parameters = infra.get_driver().get_database_instances()

    success = steps_for_instances(
        steps, instances_to_change_parameters, task,
        database_change_parameter.update_step, since_step
    )

    if success:
        database_change_parameter.set_success()
        task.update_status_for(TaskHistory.STATUS_SUCCESS, 'Done')
    else:
        database_change_parameter.set_error()
        task.update_status_for(
            TaskHistory.STATUS_ERROR,
            'Could not do change the database parameters.\nChange parameters doesn\'t have rollback'
        )