def __check_config_is_right(self):
        config = KSC_Configuration.load(utils.get_context(), self.config.id)
        if not config:
            raise Exception("create config, not write in db")
        
        if self.name != config.name or self.description != config.description:
            raise Exception("create config, name or description bad value")
        
        if self.config.config_type != '1':
            raise Exception("create config, config_type bad value")
        
        overrides = KSC_Configuration.get_configuration_overrides(utils.get_context(), self.config.id)
        
        diffs = {}
        for k, v in self.values.iteritems():
            if overrides[k] != v and float(overrides[k]) != float(v):                
                diffs[k] = (v, overrides[k])
        if len(diffs):
            raise Exception("create config, values error")
            
#         
#         if overrides != self.values:
#             raise Exception("create config, values error")
        
        datastore_version = DatastoreVersion.load_by_uuid(self.config.datastore_version_id)
        if not datastore_version:
            raise Exception("create config, bad value of datastore_version_id")
        
        if datastore_version.name != self.datastore_version:
            raise Exception("create config, bad value of datastore_version_id")
Exemple #2
0
    def unassign_configuration(self, flavor, configuration_id):
        LOG.debug("Unassigning the configuration from the instance %s"
                  % self.id)
        LOG.debug("Unassigning the configuration id %s"
                  % self.configuration.id)

        def _find_item(items, item_name):
            LOG.debug("items: %s" % items)
            LOG.debug("item_name: %s" % item_name)
            # find the item in the list
            for i in items:
                if i[0] == item_name:
                    return i

        def _convert_value(value):
            # split the value and the size e.g. 512M=['512','M']
            pattern = re.compile('(\d+)(\w+)')
            split = pattern.findall(value)
            if len(split) < 2:
                return value
            digits, size = split
            conversions = {
                'K': 1024,
                'M': 1024 ** 2,
                'G': 1024 ** 3,
            }
            return str(int(digits) * conversions[size])

        default_config = self._render_config_dict(flavor)
        args = {
            "ds_manager": self.ds_version.manager,
            "config": default_config,
        }
        LOG.debug("default %(ds_manager)s section: %(config)s" % args)
        LOG.debug("self.configuration: %s" % self.configuration.__dict__)

        overrides = {}
        config_items = KSC_Configuration.load_items(self.context, configuration_id)
        for item in config_items:
            LOG.debug("finding item(%s)" % item.__dict__)
            try:
                key, val = _find_item(default_config, item.configuration_key)
            except TypeError:
                val = None
                #restart_required = inst_models.InstanceTasks.RESTART_REQUIRED
                #self.update_db(task_status=restart_required)
            if val:
                overrides[item.configuration_key] = _convert_value(val)
        LOG.debug("setting the default variables in dict: %s" % overrides)
        self.update_overrides(overrides, remove=True)
        self.update_db(configuration_id=None)
        config_group = KSC_Configuration.load(self.context , configuration_id)
        KSC_Configuration.delete(self.context, config_group)
Exemple #3
0
    def update(self, req, body, tenant_id, id):
        LOG.info(_("Updating configuration for tenant id %s") % tenant_id)
        context = req.environ[wsgi.CONTEXT_KEY]
        group = models.Configuration.load(context, id)
        datastore_args = body["configuration"].get("datastore", {})
        datastore, datastore_version = ds_models.get_datastore_version(**datastore_args)
        instances = instances_models.DBInstance.find_all(
            tenant_id=context.tenant, configuration_id=id, deleted=False
        ).all()

        # if name/description are provided in the request body, update the
        # model with these values as well.
        if "name" in body["configuration"]:
            group.name = body["configuration"]["name"]

        if "description" in body["configuration"]:
            group.description = body["configuration"]["description"]

        """validate if params are valid"""
        is_configuration_valid = False

        validation_result = KSC_ConfigurationsController.validate_configuration(
            context, body["configuration"]["values"], datastore_manager=datastore_version.manager
        )

        if instances:
            current_config = KSC_Configuration.load(context, id)
            validation_dynamic_result = KSC_Configuration.validate_dynamic_params(
                context, current_config, instances, body["configuration"]["values"], dynamic_param=True
            )
            if validation_result or validation_dynamic_result:
                if validation_dynamic_result:
                    validation_result.update(validation_dynamic_result)
            elif not validation_result and not validation_dynamic_result:
                is_configuration_valid = True
        else:
            if not validation_result:
                is_configuration_valid = True

        result = {"is_validate_pass": is_configuration_valid, "validation_result": validation_result}

        if validation_result:
            return wsgi.Result(result, 400)
        else:
            deleted_at = datetime.utcnow()
            models.Configuration.remove_all_items(context, group.id, deleted_at)
            LOG.info(_("loaded configuration instances: %s") % instances)
            items = self.configuration_items_list(group, body["configuration"])
            models.Configuration.save(context, group, items, instances)

            result["is_validate_pass"] = is_configuration_valid
            return wsgi.Result(result, 202)
 def update(self):
     self.create()
     configuration_id = self.config.id
     values = {"myisam_sort_buffer_size":115343360,"join_buffer_size":307200,'sort_buffer_size':327680}
     valuesJson = json.dumps(values)
     name = 'update_%s' % self.config.name
     description = 'update_%s' % self.config.description
     utils.configuration_update_byclient(configuration_id, valuesJson, name, description)
     config = KSC_Configuration.load(utils.get_context(), configuration_id)
     if config == self.config:
         raise Exception("update config, something is not update, config = %s" % config)
     
     override = KSC_Configuration.get_configuration_overrides(utils.get_context(), configuration_id)
     if values == override:
         raise Exception("update config, something is not update, config override = %s" % override)
Exemple #5
0
    def edit(self, req, body, tenant_id, id):
        context = req.environ[wsgi.CONTEXT_KEY]
        group = models.Configuration.load(context, id)
        datastore_args = body["configuration"].get("datastore", {})
        datastore, datastore_version = ds_models.get_datastore_version(**datastore_args)
        instances = instances_models.DBInstance.find_all(
            tenant_id=context.tenant, configuration_id=id, deleted=False
        ).all()
        LOG.info(_("loaded configuration instances: %s") % instances)

        """validate if params are valid"""
        is_configuration_valid = False

        validation_result = KSC_ConfigurationsController.validate_configuration(
            context, body["configuration"]["values"], datastore_manager=datastore_version.manager
        )

        if instances:
            current_config = KSC_Configuration.load(context, id)
            validation_dynamic_result = (
                KSC_Configuration.validate_dynamic_params(
                    context, current_config, instances, body["configuration"]["values"], dynamic_param=True
                )
                or {}
            )
            if validation_result or validation_dynamic_result:
                validation_result.update(validation_dynamic_result)
            elif not validation_result and not validation_dynamic_result:
                is_configuration_valid = True
        else:
            if not validation_result:
                is_configuration_valid = True

        result = {"is_validate_pass": is_configuration_valid, "validation_result": validation_result}

        if validation_result:
            return wsgi.Result(result, 400)
        else:
            items = self.configuration_items_list(group, body["configuration"])
            models.Configuration.save(context, group, items, instances)

            result["is_validate_pass"] = is_configuration_valid

            return wsgi.Result(result, 202)
 def delete(self):
     self.create()
     #config_type = "1"
     #config = utils.get_config_bytenant(config_type)
     config = self.config
     utils.configuration_delete_byclient(config.id)
     is_OK = 0
     #check ...
     try:
         config = KSC_Configuration.load(utils.get_context(), config.id)
     except Exception as e:
         is_OK = 1
             
     try:
         override = KSC_Configuration.get_configuration_overrides(utils.get_context(), config.id)
     except Exception as e1:
         is_OK = is_OK + 1
     
     if is_OK != 2:
         raise Exception("delete config, no delete success..")