コード例 #1
0
    def importModel(self, spec):
        """ Import a model

    :param spec: datasource-specific value created by `exportModel`
    :type spec: dict

    :returns: datasource-specific unique metric identifier
    """
        stackSpec = spec["stackSpec"]
        aggSpec = stackSpec["aggSpec"]

        try:
            with self.connectionFactory() as conn:
                autostackObj = repository.getAutostackForNameAndRegion(
                    conn, stackSpec["name"], aggSpec["region"])
        except grok.app.exceptions.ObjectNotFoundError:
            autostackObj = self.createAutostack(stackSpec)

        modelSpec = spec["modelSpec"]
        metricSpec = modelSpec["metricSpec"]
        metricSpec["autostackId"] = autostackObj.uid

        try:
            return self.monitorMetric(modelSpec)
        except grok.app.exceptions.MetricAlreadyMonitored as e:
            self._log.warning(
                "importModel: Autostack metric already monitored; "
                "metricSpec=%s", metricSpec)
            return e.uid
コード例 #2
0
ファイル: __init__.py プロジェクト: bertdg/numenta-apps
  def importModel(self, spec):
    """ Import a model

    :param spec: datasource-specific value created by `exportModel`
    :type spec: dict

    :returns: datasource-specific unique metric identifier
    """
    stackSpec = spec["stackSpec"]
    aggSpec = stackSpec["aggSpec"]

    try:
      with self.connectionFactory() as conn:
        autostackObj = repository.getAutostackForNameAndRegion(
          conn,
          stackSpec["name"],
          aggSpec["region"])
    except grok.app.exceptions.ObjectNotFoundError:
      autostackObj = self.createAutostack(stackSpec)

    modelSpec = spec["modelSpec"]
    metricSpec = modelSpec["metricSpec"]
    metricSpec["autostackId"] = autostackObj.uid

    try:
      return self.monitorMetric(modelSpec)
    except grok.app.exceptions.MetricAlreadyMonitored as e:
      self._log.warning("importModel: Autostack metric already monitored; "
                        "metricSpec=%s", metricSpec)
      return e.uid
コード例 #3
0
ファイル: __init__.py プロジェクト: karimilli95/numenta-apps
    def getInstanceNameForModelSpec(self, spec):
        """ Get canonical instance name from a model spec

    :param modelSpec: Model specification or import model specification
    :type modelSpec: JSONifiable dict

    :returns: Canonical instance name; None if autostack doesn't exist
    :rtype: str or None
    """
        if "metricSpec" in spec:
            autostackId = spec["metricSpec"]["autostackId"]
        else:
            # Proceed as if for an import-model-spec
            stackSpec = spec["stackSpec"]
            aggSpec = stackSpec["aggSpec"]

            try:
                with self.connectionFactory() as conn:
                    autostackObj = repository.getAutostackForNameAndRegion(
                        conn, stackSpec["name"], aggSpec["region"])
            except grok.app.exceptions.ObjectNotFoundError:
                return None
            else:
                autostackId = autostackObj.uid

        return self._getCanonicalResourceName(autostackId)
コード例 #4
0
ファイル: __init__.py プロジェクト: karimilli95/numenta-apps
  def getInstanceNameForModelSpec(self, spec):
    """ Get canonical instance name from a model spec

    :param modelSpec: Model specification or import model specification
    :type modelSpec: JSONifiable dict

    :returns: Canonical instance name; None if autostack doesn't exist
    :rtype: str or None
    """
    if "metricSpec" in spec:
      autostackId = spec["metricSpec"]["autostackId"]
    else:
      # Proceed as if for an import-model-spec
      stackSpec = spec["stackSpec"]
      aggSpec = stackSpec["aggSpec"]

      try:
        with self.connectionFactory() as conn:
          autostackObj = repository.getAutostackForNameAndRegion(
            conn,
            stackSpec["name"],
            aggSpec["region"])
      except grok.app.exceptions.ObjectNotFoundError:
        return None
      else:
        autostackId = autostackObj.uid

    return self._getCanonicalResourceName(autostackId)