示例#1
0
    def _create_instances(context, db_info, datastore, datastore_version,
                          instances, extended_properties, locality):
        redis_conf = CONF.get(datastore_version.manager)
        ephemeral_enabled = redis_conf.device_path
        volume_enabled = redis_conf.volume_support

        num_instances = len(instances)

        models.validate_instance_flavors(context, instances, volume_enabled,
                                         ephemeral_enabled)

        total_volume_allocation = models.get_required_volume_size(
            instances, volume_enabled)

        models.assert_homogeneous_cluster(instances)

        models.validate_instance_nics(context, instances)

        name_index = 1
        for instance in instances:
            if not instance.get('name'):
                instance['name'] = "%s-member-%s" % (db_info.name, name_index)
                name_index += 1

        # Check quotas
        quota_request = {
            'instances': num_instances,
            'volumes': total_volume_allocation
        }
        check_quotas(context.project_id, quota_request)

        # Creating member instances
        return [
            inst_models.Instance.create(
                context,
                instance['name'],
                instance['flavor_id'],
                datastore_version.image_id, [], [],
                datastore,
                datastore_version,
                instance.get('volume_size'),
                None,
                instance.get('availability_zone', None),
                instance.get('nics', None),
                configuration_id=None,
                cluster_config={
                    "id": db_info.id,
                    "instance_type": "member"
                },
                volume_type=instance.get('volume_type', None),
                modules=instance.get('modules'),
                locality=locality,
                region_name=instance.get('region_name'))
            for instance in instances
        ]
示例#2
0
    def create(cls, context, name, datastore, datastore_version, instances,
               extended_properties, locality, configuration
              ):  # pylint: disable=too-many-arguments, too-many-locals
        """Create Clusters API endpoint.

        main function to create a cluster is here
        https://github.com/openstack/trove/blob/master/trove/cluster/service.py#L162-L234
        """

        # 1. validates args
        if context is None:
            LOG.error("no context")
            return None
        if name is None:
            LOG.error("no name")
            return None
        if datastore is None:
            LOG.error("no datastore")
            return None
        if datastore_version is None:
            LOG.error("no datastore_version")
            return None
        if instances is None:
            LOG.error("no instances")
            return None
        models.assert_homogeneous_cluster(instances)
        manager_conf = CONF.get(datastore_version.manager)
        models.validate_instance_flavors(context, instances,
                                         manager_conf.volume_support,
                                         manager_conf.device_path)
        models.validate_instance_nics(context, instances)

        # 2. Insert a cluster data to clusters table
        db_info = models.DBCluster.create(
            name=name,
            tenant_id=context.project_id,
            datastore_version_id=datastore_version.id,
            configuration_id=configuration,
            task_status=ClusterTasks.BUILDING_INITIAL)

        # 3. Create instances in OpenStack
        cls._create_insts(context, db_info.id, db_info.name, datastore,
                          datastore_version, instances, locality,
                          configuration)

        # 4. Calling taskmanager to further proceed for cluster-configuration
        LOG.debug(
            "Calling taskmanager to further proceed for "
            "cluster-configuration of %s", db_info.id)
        task_api.load(context,
                      datastore_version.manager).create_cluster(db_info.id)

        # 5. Returns cluster instance to render HTTP response.
        return K2hdkcCluster(context, db_info, datastore, datastore_version)
示例#3
0
    def _validate_cluster_instances(context, instances, datastore,
                                    datastore_version):
        """Validate the flavor and volume"""
        ds_conf = CONF.get(datastore_version.manager)
        num_instances = len(instances)

        # Checking volumes and get delta for quota check
        cluster_models.validate_instance_flavors(context, instances,
                                                 ds_conf.volume_support,
                                                 ds_conf.device_path)

        req_volume_size = cluster_models.get_required_volume_size(
            instances, ds_conf.volume_support)

        cluster_models.assert_homogeneous_cluster(instances)

        deltas = {'instances': num_instances, 'volumes': req_volume_size}

        # quota check
        check_quotas(context.tenant, deltas)

        # Checking networks are same for the cluster
        cluster_models.validate_instance_nics(context, instances)
示例#4
0
文件: api.py 项目: wffeige/trove
    def _create_cluster_instances(cls, context, cluster_id, cluster_name,
                                  datastore, datastore_version, instances,
                                  extended_properties, locality,
                                  configuration_id):
        LOG.debug("Processing a request for new cluster instances.")

        cassandra_conf = CONF.get(datastore_version.manager)
        eph_enabled = cassandra_conf.device_path
        vol_enabled = cassandra_conf.volume_support

        # Validate instance flavors.
        models.validate_instance_flavors(context, instances, vol_enabled,
                                         eph_enabled)

        # Compute the total volume allocation.
        req_volume_size = models.get_required_volume_size(
            instances, vol_enabled)

        # Check requirements against quota.
        num_new_instances = len(instances)
        deltas = {'instances': num_new_instances, 'volumes': req_volume_size}
        models.assert_homogeneous_cluster(instances)
        check_quotas(context.tenant, deltas)

        # Checking networks are same for the cluster
        models.validate_instance_nics(context, instances)

        # Creating member instances.
        num_instances = len(
            CassandraClusterTasks.find_cluster_node_ids(cluster_id))
        new_instances = []
        for instance_idx, instance in enumerate(instances, num_instances + 1):
            instance_az = instance.get('availability_zone', None)

            member_config = {
                "id": cluster_id,
                "instance_type": "member",
                "dc": cls.DEFAULT_DATA_CENTER,
                "rack": instance_az or cls.DEFAULT_RACK
            }

            instance_name = instance.get('name')
            if not instance_name:
                instance_name = cls._build_instance_name(
                    cluster_name, member_config['dc'], member_config['rack'],
                    instance_idx)

            new_instance = inst_models.Instance.create(
                context,
                instance_name,
                instance['flavor_id'],
                datastore_version.image_id, [], [],
                datastore,
                datastore_version,
                instance['volume_size'],
                None,
                nics=instance.get('nics', None),
                availability_zone=instance_az,
                configuration_id=configuration_id,
                cluster_config=member_config,
                volume_type=instance.get('volume_type', None),
                modules=instance.get('modules'),
                locality=locality,
                region_name=instance.get('region_name'))

            new_instances.append(new_instance)

        return new_instances
示例#5
0
    def create(cls, context, name, datastore, datastore_version,
               instances, extended_properties, locality, configuration):

        if configuration:
            raise exception.ConfigurationNotSupported()

        # TODO(amcreynolds): consider moving into CONF and even supporting
        # TODO(amcreynolds): an array of values, e.g. [3, 5, 7]
        # TODO(amcreynolds): or introduce a min/max num_instances and set
        # TODO(amcreynolds): both to 3
        num_instances = len(instances)
        if num_instances != 3:
            raise exception.ClusterNumInstancesNotSupported(num_instances=3)

        mongo_conf = CONF.get(datastore_version.manager)

        num_configsvr = int(extended_properties.get(
            'num_configsvr', mongo_conf.num_config_servers_per_cluster))
        num_mongos = int(extended_properties.get(
            'num_mongos', mongo_conf.num_query_routers_per_cluster))

        delta_instances = num_instances + num_configsvr + num_mongos

        models.validate_instance_flavors(
            context, instances, mongo_conf.volume_support,
            mongo_conf.device_path)
        models.assert_homogeneous_cluster(instances)

        flavor_id = instances[0]['flavor_id']

        volume_size = instances[0].get('volume_size', None)
        volume_type = instances[0].get('volume_type', None)

        configsvr_vsize = int(extended_properties.get(
            'configsvr_volume_size', mongo_conf.config_servers_volume_size))
        configsvr_vtype = extended_properties.get('configsvr_volume_type',
                                                  volume_type)

        mongos_vsize = int(extended_properties.get(
            'mongos_volume_size', mongo_conf.query_routers_volume_size))
        mongos_vtype = extended_properties.get('mongos_volume_type',
                                               volume_type)

        all_instances = (instances
                         + [{'volume_size': configsvr_vsize}] * num_configsvr
                         + [{'volume_size': mongos_vsize}] * num_mongos)
        req_volume_size = models.get_required_volume_size(
            all_instances, mongo_conf.volume_support)

        deltas = {'instances': delta_instances, 'volumes': req_volume_size}
        check_quotas(context.project_id, deltas)

        # Checking networks are same for the cluster
        models.validate_instance_nics(context, instances)

        nics = instances[0].get('nics', None)

        azs = [instance.get('availability_zone', None)
               for instance in instances]

        regions = [instance.get('region_name', None)
                   for instance in instances]

        db_info = models.DBCluster.create(
            name=name, tenant_id=context.project_id,
            datastore_version_id=datastore_version.id,
            task_status=ClusterTasks.BUILDING_INITIAL)

        replica_set_name = "rs1"

        member_config = {"id": db_info.id,
                         "shard_id": utils.generate_uuid(),
                         "instance_type": "member",
                         "replica_set_name": replica_set_name}

        configsvr_config = {"id": db_info.id,
                            "instance_type": "config_server"}

        mongos_config = {"id": db_info.id,
                         "instance_type": "query_router"}

        if mongo_conf.cluster_secure:
            cluster_key = utils.generate_random_password()
            member_config['key'] = cluster_key
            configsvr_config['key'] = cluster_key
            mongos_config['key'] = cluster_key

        for i in range(0, num_instances):
            instance_name = "%s-%s-%s" % (name, replica_set_name, str(i + 1))
            inst_models.Instance.create(context, instance_name,
                                        flavor_id,
                                        datastore_version.image_id,
                                        [], [], datastore,
                                        datastore_version,
                                        volume_size, None,
                                        availability_zone=azs[i],
                                        nics=nics,
                                        configuration_id=None,
                                        cluster_config=member_config,
                                        volume_type=volume_type,
                                        modules=instances[i].get('modules'),
                                        locality=locality,
                                        region_name=regions[i])

        for i in range(1, num_configsvr + 1):
            instance_name = "%s-%s-%s" % (name, "configsvr", str(i))
            inst_models.Instance.create(context, instance_name,
                                        flavor_id,
                                        datastore_version.image_id,
                                        [], [], datastore,
                                        datastore_version,
                                        configsvr_vsize, None,
                                        availability_zone=None,
                                        nics=nics,
                                        configuration_id=None,
                                        cluster_config=configsvr_config,
                                        volume_type=configsvr_vtype,
                                        locality=locality,
                                        region_name=regions[i % num_instances]
                                        )

        for i in range(1, num_mongos + 1):
            instance_name = "%s-%s-%s" % (name, "mongos", str(i))
            inst_models.Instance.create(context, instance_name,
                                        flavor_id,
                                        datastore_version.image_id,
                                        [], [], datastore,
                                        datastore_version,
                                        mongos_vsize, None,
                                        availability_zone=None,
                                        nics=nics,
                                        configuration_id=None,
                                        cluster_config=mongos_config,
                                        volume_type=mongos_vtype,
                                        locality=locality,
                                        region_name=regions[i % num_instances]
                                        )

        task_api.load(context, datastore_version.manager).create_cluster(
            db_info.id)

        return MongoDbCluster(context, db_info, datastore, datastore_version)
示例#6
0
文件: api.py 项目: wffeige/trove
    def _create_instances(context,
                          db_info,
                          datastore,
                          datastore_version,
                          instances,
                          extended_properties,
                          locality,
                          new_cluster=True):
        vertica_conf = CONF.get(datastore_version.manager)
        num_instances = len(instances)

        existing = inst_models.DBInstance.find_all(cluster_id=db_info.id,
                                                   deleted=False).all()
        num_existing = len(existing)

        # Matching number of instances with configured cluster_member_count
        if (new_cluster
                and num_instances != vertica_conf.cluster_member_count):
            raise exception.ClusterNumInstancesNotSupported(
                num_instances=vertica_conf.cluster_member_count)

        models.validate_instance_flavors(context, instances,
                                         vertica_conf.volume_support,
                                         vertica_conf.device_path)

        req_volume_size = models.get_required_volume_size(
            instances, vertica_conf.volume_support)
        models.assert_homogeneous_cluster(instances)

        models.validate_instance_nics(context, instances)

        deltas = {'instances': num_instances, 'volumes': req_volume_size}

        check_quotas(context.tenant, deltas)

        flavor_id = instances[0]['flavor_id']
        volume_size = instances[0].get('volume_size', None)
        volume_type = instances[0].get('volume_type', None)

        nics = [instance.get('nics', None) for instance in instances]

        azs = [
            instance.get('availability_zone', None) for instance in instances
        ]

        regions = [instance.get('region_name', None) for instance in instances]

        # Creating member instances
        minstances = []
        for i in range(0, num_instances):
            if i == 0 and new_cluster:
                member_config = {"id": db_info.id, "instance_type": "master"}
            else:
                member_config = {"id": db_info.id, "instance_type": "member"}
            instance_name = "%s-member-%s" % (db_info.name,
                                              str(i + num_existing + 1))
            minstances.append(
                inst_models.Instance.create(
                    context,
                    instance_name,
                    flavor_id,
                    datastore_version.image_id, [], [],
                    datastore,
                    datastore_version,
                    volume_size,
                    None,
                    nics=nics[i],
                    availability_zone=azs[i],
                    configuration_id=None,
                    cluster_config=member_config,
                    volume_type=volume_type,
                    modules=instances[i].get('modules'),
                    locality=locality,
                    region_name=regions[i]))
        return minstances