Exemplo n.º 1
0
    def init(cls):
        """ Determine the quota and save it in the "quota" config. NOTE: this
    should be called once *before* starting Grok services.
    """
        editionType = product.get("edition", "type")

        quotaConfig = QuotaConfig()

        if editionType == "free":
            print("As of Grok 1.5, the 'free' edition is no longer supported; "
                  "using standard edition quotas instead")
            _getLogger().warn("Called updateQuota on a 'free' edition")

        hostInfo = cls._getHostInfo()
        option = "%s.%s.%s" % (
            editionType,
            hostInfo["infrastructureType"],
            hostInfo["instanceType"],
        )

        instanceQuota = quotaConfig.getint("instance_quota_table", option)

        overrideConfig = QuotaConfig(mode=QuotaConfig.MODE_OVERRIDE_ONLY)
        if not overrideConfig.has_section("actual"):
            overrideConfig.add_section("actual")
        overrideConfig.set("actual", "instance_quota", str(instanceQuota))
        overrideConfig.save()

        _getLogger().info(
            "Initialized instance quota; edition=%s; "
            "instanceQuota=%s", editionType, instanceQuota)
Exemplo n.º 2
0
  def init(cls):
    """ Determine the quota and save it in the "quota" config. NOTE: this
    should be called once *before* starting Grok services.
    """
    editionType = product.get("edition", "type")

    quotaConfig = QuotaConfig()

    if editionType == "free":
      print ("As of Grok 1.5, the 'free' edition is no longer supported; "
        "using standard edition quotas instead")
      _getLogger().warn("Called updateQuota on a 'free' edition")

    hostInfo = cls._getHostInfo()
    option = "%s.%s.%s" % (editionType,
                           hostInfo["infrastructureType"],
                           hostInfo["instanceType"],)

    instanceQuota = quotaConfig.getint("instance_quota_table", option)

    overrideConfig = QuotaConfig(mode=QuotaConfig.MODE_OVERRIDE_ONLY)
    if not overrideConfig.has_section("actual"):
      overrideConfig.add_section("actual")
    overrideConfig.set("actual", "instance_quota", str(instanceQuota))
    overrideConfig.save()

    _getLogger().info("Initialized instance quota; edition=%s; "
                      "instanceQuota=%s", editionType, instanceQuota)
Exemplo n.º 3
0
def checkQuotaForInstanceAndRaise(conn, instanceName):
    """ Perform instance quota check and raise QuotaError exception if request to
  create a model for `instanceName` would result in a new "instance" being
  created beyond quota.

  This function answers the question:

    Is there room to add a new model for a new, or existing instance?

  And raises an exception if the answer is no.

  :param conn: SQLAlchemy connection object
  :type conn: sqlalchemy.engine.Connection
  :param instanceName: Instance name
  :type instanceName str:

  :raises: grok.app.exceptions.QuotaError
  """
    instanceCount = repository.getInstanceCount(conn)
    instanceQuota = Quota.getInstanceQuota()

    if instanceCount >= instanceQuota:
        if not repository.listMetricIDsForInstance(conn, instanceName):
            raise QuotaError(
                "Server limit exceeded; edition=%s; count=%i; limit=%i." %
                (product.get("edition",
                             "type").title(), instanceCount, instanceQuota))
Exemplo n.º 4
0
def checkQuotaForInstanceAndRaise(conn, instanceName):
  """ Perform instance quota check and raise QuotaError exception if request to
  create a model for `instanceName` would result in a new "instance" being
  created beyond quota.

  This function answers the question:

    Is there room to add a new model for a new, or existing instance?

  And raises an exception if the answer is no.

  :param conn: SQLAlchemy connection object
  :type conn: sqlalchemy.engine.Connection
  :param instanceName: Instance name
  :type instanceName str:

  :raises: grok.app.exceptions.QuotaError
  """
  instanceCount = repository.getInstanceCount(conn)
  instanceQuota = Quota.getInstanceQuota()

  if instanceCount >= instanceQuota:
    if not repository.listMetricIDsForInstance(conn, instanceName):
      raise QuotaError(
        "Server limit exceeded; edition=%s; count=%i; limit=%i." % (
          product.get("edition", "type").title(), instanceCount,
          instanceQuota))