Esempio n. 1
0
 def action(self, req, body, tenant_id, id):
     LOG.debug("Committing Action Against Cluster for "
               "Tenant '%s'" % tenant_id)
     LOG.info(_("req : '%s'\n\n") % req)
     LOG.info(_("id : '%s'\n\n") % id)
     if not body:
         raise exception.BadRequest(_("Invalid request body."))
     context = req.environ[wsgi.CONTEXT_KEY]
     cluster = models.Cluster.load(context, id)
     manager = cluster.datastore_version.manager
     api_strategy = strategy.load_api_strategy(manager)
     _actions = api_strategy.cluster_controller_actions
     selected_action = None
     for key in body:
         if key in _actions:
             selected_action = _actions[key]
             break
     else:
         message = _(
             "No action '%(action)s' supplied "
             "by strategy for manager '%(manager)s'") % ({
                 'action': key,
                 'manager': manager
             })
         raise exception.TroveError(message)
     return selected_action(cluster, body)
Esempio n. 2
0
 def action(self, req, body, tenant_id, id):
     LOG.debug(("Committing Action Against Cluster for "
                "Tenant '%(tenant_id)s'\n"
                "req : '%(req)s'\n\nid : '%(id)s'\n\n") %
               {"req": req, "id": id, "tenant_id": tenant_id})
     if not body:
         raise exception.BadRequest(_("Invalid request body."))
     context = req.environ[wsgi.CONTEXT_KEY]
     cluster = models.Cluster.load(context, id)
     manager = cluster.datastore_version.manager
     api_strategy = strategy.load_api_strategy(manager)
     _actions = api_strategy.cluster_controller_actions
     selected_action = None
     for key in body:
         if key in _actions:
             selected_action = _actions[key]
             break
     else:
         message = _("No action '%(action)s' supplied "
                     "by strategy for manager '%(manager)s'") % (
                         {'action': key, 'manager': manager})
         raise exception.TroveError(message)
     cluster = selected_action(cluster, body)
     if cluster:
         view = views.load_view(cluster, req=req, load_servers=False)
         wsgi_result = wsgi.Result(view.data(), 202)
     else:
         wsgi_result = wsgi.Result(None, 202)
     return wsgi_result
Esempio n. 3
0
 def create(cls, context, name, datastore, datastore_version, instances,
            extended_properties, locality):
     locality = srv_grp.ServerGroup.build_scheduler_hint(
         context, locality, name)
     api_strategy = strategy.load_api_strategy(datastore_version.manager)
     return api_strategy.cluster_class.create(context, name, datastore,
                                              datastore_version, instances,
                                              extended_properties, locality)
Esempio n. 4
0
 def create(cls, context, name, datastore, datastore_version,
            instances, extended_properties, locality):
     locality = srv_grp.ServerGroup.build_scheduler_hint(
         context, locality, name)
     api_strategy = strategy.load_api_strategy(datastore_version.manager)
     return api_strategy.cluster_class.create(context, name, datastore,
                                              datastore_version, instances,
                                              extended_properties,
                                              locality)
Esempio n. 5
0
 def load(cls, context, cluster_id, clazz=None):
     try:
         db_info = DBCluster.find_by(context=context, id=cluster_id, deleted=False)
     except exception.ModelNotFoundError:
         raise exception.ClusterNotFound(cluster=cluster_id)
     if not clazz:
         ds_version = datastore_models.DatastoreVersion.load_by_uuid(db_info.datastore_version_id)
         manager = ds_version.manager
         clazz = strategy.load_api_strategy(manager).cluster_class
     return clazz(context, db_info)
Esempio n. 6
0
 def load(cls, context, cluster_id, clazz=None):
     try:
         db_info = DBCluster.find_by(context=context, id=cluster_id,
                                     deleted=False)
     except exception.ModelNotFoundError:
         raise exception.ClusterNotFound(cluster=cluster_id)
     if not clazz:
         ds_version = (datastore_models.DatastoreVersion.
                       load_by_uuid(db_info.datastore_version_id))
         manager = ds_version.manager
         clazz = strategy.load_api_strategy(manager).cluster_class
     return clazz(context, db_info)
Esempio n. 7
0
    def action(self, req, body, tenant_id, id):
        LOG.debug("Committing Action Against Cluster for "
                  "Tenant '%s'" % tenant_id)
        LOG.info(_("req : '%s'\n\n") % req)
        LOG.info(_("id : '%s'\n\n") % id)

        if not body:
            raise exception.BadRequest(_("Invalid request body."))

        context = req.environ[wsgi.CONTEXT_KEY]
        cluster = models.Cluster.load(context, id)
        manager = cluster.datastore_version.manager
        api_strategy = strategy.load_api_strategy(manager)
        _actions = api_strategy.cluster_controller_actions

        def find_action_key():
            for key in body:
                if key in _actions:
                    return key
            else:
                message = _("No action '%(action)s' supplied "
                            "by strategy for manager '%(manager)s'") % (
                                {
                                    'action': key,
                                    'manager': manager
                                })
                raise exception.TroveError(message)

        action_key = find_action_key()
        if action_key == 'grow':
            context.notification = notification.DBaaSClusterGrow(context,
                                                                 request=req)
        elif action_key == 'shrink':
            context.notification = notification.DBaaSClusterShrink(context,
                                                                   request=req)
        with StartNotification(context, cluster_id=id):
            selected_action = _actions[action_key]
            cluster = selected_action(cluster, body)

        if cluster:
            view = views.load_view(cluster, req=req, load_servers=False)
            wsgi_result = wsgi.Result(view.data(), 202)
        else:
            wsgi_result = wsgi.Result(None, 202)

        return wsgi_result
Esempio n. 8
0
    def action(self, req, body, tenant_id, id):
        LOG.debug("Committing Action Against Cluster for "
                  "Tenant '%s'" % tenant_id)
        LOG.info(_("req : '%s'\n\n") % req)
        LOG.info(_("id : '%s'\n\n") % id)

        if not body:
            raise exception.BadRequest(_("Invalid request body."))

        context = req.environ[wsgi.CONTEXT_KEY]
        cluster = models.Cluster.load(context, id)
        manager = cluster.datastore_version.manager
        api_strategy = strategy.load_api_strategy(manager)
        _actions = api_strategy.cluster_controller_actions

        def find_action_key():
            for key in body:
                if key in _actions:
                    return key
            else:
                message = _("No action '%(action)s' supplied "
                            "by strategy for manager '%(manager)s'") % (
                                {'action': key, 'manager': manager})
                raise exception.TroveError(message)

        action_key = find_action_key()
        if action_key == 'grow':
            context.notification = notification.DBaaSClusterGrow(context,
                                                                 request=req)
        elif action_key == 'shrink':
            context.notification = notification.DBaaSClusterShrink(context,
                                                                   request=req)
        with StartNotification(context, cluster_id=id):
            selected_action = _actions[action_key]
            cluster = selected_action(cluster, body)

        if cluster:
            view = views.load_view(cluster, req=req, load_servers=False)
            wsgi_result = wsgi.Result(view.data(), 202)
        else:
            wsgi_result = wsgi.Result(None, 202)

        return wsgi_result
Esempio n. 9
0
 def action(self, req, body, tenant_id, id):
     LOG.debug("Committing Action Against Cluster for " "Tenant '%s'" % tenant_id)
     LOG.info(_("req : '%s'\n\n") % req)
     LOG.info(_("id : '%s'\n\n") % id)
     if not body:
         raise exception.BadRequest(_("Invalid request body."))
     context = req.environ[wsgi.CONTEXT_KEY]
     cluster = models.Cluster.load(context, id)
     manager = cluster.datastore_version.manager
     api_strategy = strategy.load_api_strategy(manager)
     _actions = api_strategy.cluster_controller_actions
     selected_action = None
     for key in body:
         if key in _actions:
             selected_action = _actions[key]
             break
     else:
         message = _("No action '%(action)s' supplied " "by strategy for manager '%(manager)s'") % (
             {"action": key, "manager": manager}
         )
         raise exception.TroveError(message)
     return selected_action(cluster, body)
Esempio n. 10
0
 def create(cls, context, name, datastore, datastore_version,
            instances, extended_properties):
     api_strategy = strategy.load_api_strategy(datastore_version.manager)
     return api_strategy.cluster_class.create(context, name, datastore,
                                              datastore_version, instances,
                                              extended_properties)
Esempio n. 11
0
def load_view(cluster, req, load_servers=True):
    manager = cluster.datastore_version.manager
    return strategy.load_api_strategy(manager).cluster_view_class(
        cluster, req, load_servers)
Esempio n. 12
0
def load_view(cluster, req, load_servers=True):
    manager = cluster.datastore_version.manager
    return strategy.load_api_strategy(manager).cluster_view_class(
        cluster, req, load_servers)
Esempio n. 13
0
 def create(cls, context, name, datastore, datastore_version, instances):
     api_strategy = strategy.load_api_strategy(datastore_version.manager)
     return api_strategy.cluster_class.create(context, name, datastore,
                                              datastore_version, instances)