Exemplo n.º 1
0
    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")
Exemplo n.º 2
0
 def patch(self):
     if not self.config:
         self.create()
     configuration_id = self.config.id
     values = json.dumps({"myisam_sort_buffer_size":116391936,"join_buffer_size":409600})
     utils.configuration_patch_byclient(configuration_id, values)
     override = KSC_Configuration.get_configuration_overrides(utils.get_context(), configuration_id)
     if values == override:
         raise Exception("patch config, something is not update,  override = %s" % override)
Exemplo n.º 3
0
    def patch_new(self):
        if not self.config:
            self.create_new()
        configuration_id = self.config.id
        values = {"myisam_sort_buffer_size":'xxx',"join_buffer_size":'xxx'}
#         values = json.dumps({"myisam_sort_buffer_size":116391936,"join_buffer_size":409600})
        utils.configuration_patch_byclient(configuration_id, json.dumps(values))
        override = KSC_Configuration.get_configuration_overrides(utils.get_context(), configuration_id)
        for k, v in values.iteritems():
            if override.get(k) != v:
        
#         if values == override:
                raise Exception("patch config, something is not update,  override = %s" % override)        
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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..")
Exemplo n.º 6
0
    def create_instance(self, flavor, image_id, databases, users,
                        service_type, volume_size, security_groups,
                        backup_id, instance_type, ignore_hosts=None,
                        master_id=None, extend=None):

        if instance_type==DBInstanceType.STANDBY or instance_type==DBInstanceType.READ_REPLI:
            if master_id is None:
                raise Exception("when instance_type is STANDBY or RR, The master_id can't none")

        availability_zone=None
        overrides = {}
        if extend != None:
            availability_zone=extend.get('availability_zone', None)
            ds_version_id = extend.get('datastore_version_id', None)
            overrides = extend.get('overrides', {})

        self.update_db(task_status=InstanceTasks.BUILDING_SERVER)
        try:
            server, volume_info = self._create_server_volume_individually(
                flavor,
                image_id,
                security_groups,
                service_type,
                ignore_hosts, availability_zone)
        except Exception as e:
            self.set_servicestatus(ServiceStatuses.UNKNOWN)
            raise e

        try:
            configuration_id =self.db_info.configuration_id
            LOG.debug("Prepare task  instance id = %s,  configuration id =%s" % (self.id, configuration_id))
            overrides = KSC_Configuration.get_configuration_overrides(self.context, configuration_id)
        except Exception:
            pass

        self.update_db(task_status=InstanceTasks.GUEST_PREPARE)
        LOG.info("======= > groupid %s" % self.group_id)
        group = InstanceGroup.get_by_groupid(self.context, self.group_id)
        sys_variables = {"port" : group.db_port, "read_only" : "OFF" if instance_type in (DBInstanceType.MASTER, DBInstanceType.SINGLE) else "ON"}
        overrides.update(sys_variables)
        config = self._render_config(flavor)
        overrides_config = self._render_override_config(flavor, overrides)

        self._guest_prepare(server, flavor['ram'], volume_info,
                            databases, users, backup_id,
                            config.config_contents,
                            overrides_contents = overrides_config.config_contents)

        try:
            utils.poll_until(self._service_is_active,
                             sleep_time=USAGE_SLEEP_TIME,
                             time_out=USAGE_TIMEOUT)
        except Exception as e:
            self.set_servicestatus(ServiceStatuses.UNKNOWN)
            raise e

        group_item = InstanceGroupItem.get_by_instance_id(self.context, self.id)
        group_id = group_item.group_id

        self.update_db(task_status=InstanceTasks.CONFIG_MYSQL)
        if instance_type==DBInstanceType.STANDBY or instance_type==DBInstanceType.READ_REPLI:
            if instance_type==DBInstanceType.STANDBY:
                self._update_instance_type(master_id, DBInstanceType.MASTER)

            self._update_instance_type(self.id, instance_type)
            self._relocate_master(master_id,self.id,backup_id)

            #when upgrade single to ha
            if instance_type == DBInstanceType.STANDBY:
                master_group_item = InstanceGroupItem.get_by_instance_id(self.context,master_id)
                InstanceGroupItem.update_type(self.context, item_id=master_group_item.id, type=DBInstanceType.MASTER)

        if instance_type==DBInstanceType.SINGLE or instance_type==DBInstanceType.MASTER:
            self._create_master_user(instance_id=self.id, user=extend.get('admin_user'), \
                                     password=extend.get('admin_password'))

            self._update_instance_type(self.id, instance_type)


        if instance_type==DBInstanceType.SINGLE or instance_type==DBInstanceType.MASTER:
            try:
                self.update_db(task_status=InstanceTasks.BACKUPING)
                expiretime = AutoBackup.get_autobackup_expiretime(self.context, group_id)
                backup_name = self._backup_name(instance_id=self.id)


                # Fore. 2014/07/02 Get Service Image ID from datastore version 
                #                 _type = self.service_type
                #                 _image = ServiceImage.find_by(self.context,service_name=_type)
                #ds, ds_version = ds_models.get_datastore_version(type = None, version = ds_version_id)
                #service_image_id = image_id

                desc = 'Init backup for new instance'
                Backup.create(context=self.context, instance=self.id,
                              name=backup_name, description=desc, group_id=group_id,
                              backup_type=BackupType.AUTOBACKUP, expire_at=expiretime,init=True,service_image_id=image_id)
            except Exception as e:
                msg = "Error creating backup for instance %s %s" % (self.id,utils.get_traceback_stack())
                LOG.error(msg)

        self.update_db(task_status=InstanceTasks.SETIOTUNE)
        LOG.debug("Set block iotune for instance %s ." % self.id)

        self._set_blkiotune(flavor)

        if instance_type!=DBInstanceType.STANDBY:
            if CONF.trove_vip_support:
                self.update_db(task_status=InstanceTasks.ALLOCATE_VIP)
                try:
                    rip = self._get_instance_ip(self.id)
                    vip = InstanceVip.allocate(self.context,instance_id=self.id,rip = rip)
                    LOG.debug("Allocated vip %s for instance %s"%(vip, self.id))
                except Exception as e:
                    self.set_servicestatus(ServiceStatuses.UNKNOWN)
                    raise e

        self.update_db(deleted=False,task_status=InstanceTasks.NONE)

        LOG.info("create instance_id:%s,notify monitor,autobackup" % self.id)
        group_rpcapi.API(self.context).group_update(group_id)
        self.send_usage_event('create', instance_size=flavor['ram'])