コード例 #1
0
ファイル: sds_client.py プロジェクト: sukhdev1103/Qi-Samples
    def get_or_create_type(self, namespace_id, event_type):
        """Tells Sds Service to create a type based on local 'type' or get if existing type matches"""
        if namespace_id is None:
            raise TypeError
        if event_type is None or not isinstance(event_type, SdsType):
            raise TypeError

        req_url = self.url + self.__typesPath.format(tenant_id=self.tenantId,
                                                     namespace_id=namespace_id,
                                                     type_id=event_type.Id)
        response = requests.post(url=req_url,
                                 data=event_type.to_json(),
                                 headers=self.__sds_headers())
        if response.status_code < 200 or response.status_code >= 300:
            response.close()
            cleanup(self, namespace_id, self.type_names)
            raise SdsError(
                "Failed to create type, {type_id}. {status}:{reason}".format(
                    type_id=event_type.Id,
                    status=response.status_code,
                    reason=response.text))

        event_type = SdsType.from_json(json.loads(response.content))
        response.close()
        return event_type
コード例 #2
0
ファイル: sds_client.py プロジェクト: sukhdev1103/Qi-Samples
    def get_stream_type(self, namespace_id, stream_id):
        """Retrieves a stream specified by 'stream_id' from the Sds Service"""
        if namespace_id is None:
            raise TypeError
        if stream_id is None:
            raise TypeError

        response = requests.get(
            self.url + self.__streamsPath.format(tenant_id=self.tenantId,
                                                 namespace_id=namespace_id,
                                                 stream_id=stream_id) +
            "/Type",
            headers=self.__sds_headers())
        if response.status_code < 200 or response.status_code >= 300:
            response.close()
            cleanup(self, namespace_id, self.type_names)
            raise SdsError(
                "Failed to get SdsStream, {stream_id}. {status}:{reason}".
                format(stream_id=stream_id,
                       status=response.status_code,
                       reason=response.text))

        event_type = SdsType.from_json(json.loads(response.content))
        response.close()
        return event_type
コード例 #3
0
ファイル: sds_client.py プロジェクト: sukhdev1103/Qi-Samples
    def get_types(self, namespace_id, skip=0, count=100):
        """Retrieves a list of types associated with the specified 'namespace_id' under the current tenant"""
        if namespace_id is None:
            raise TypeError

        response = requests.get(
            self.url + self.__getTypesPath.format(tenant_id=self.tenantId,
                                                  namespace_id=namespace_id,
                                                  skip=skip,
                                                  count=count),
            headers=self.__sds_headers())
        if response.status_code < 200 or response.status_code >= 300:
            response.close()
            cleanup(self, namespace_id, self.type_names)
            raise SdsError(
                "Failed to get all SdsTypes. {status}:{reason}".format(
                    status=response.status_code, reason=response.text))

        types = json.loads(response.content)
        results = []
        for t in types:
            results.append(SdsType.from_json(t))
        response.close()
        return results
コード例 #4
0
    def init_type(self, type_id, prop_names):
        """Prepares a new  SdsType object for value population"""
        sds_type = SdsType()
        sds_type.Id = type_id
        sds_type.name = type_id
        sds_type.description = "This is a sample SDS type for storing " \
                               "{} events".format(sds_type.name)

        # Please refer to the following link for an up-to-date listing of
        # type codes when assigning a type code to a new SdsType:
        # osisoft-edge.readthedocs.io/en/latest/Qi_Types.html#sdstypecode
        sds_type.sds_type_code = 1
        sds_type.Properties = []

        double_type = SdsType()
        double_type.Id = 'double_type'
        double_type.sds_type_code = 14

        date_time_type = SdsType()
        date_time_type.Id = "date_time_type"
        date_time_type.sds_type_code = 16

        time_prop = SdsTypeProperty()
        time_prop.Id = 'Time'
        time_prop.SdsType = date_time_type
        time_prop.IsKey = True
        sds_type.Properties.append(time_prop)

        for prop_name in prop_names:
            prop = SdsTypeProperty()
            prop.Id = prop_name
            prop.Name = prop_name
            prop.SdsType = double_type
            sds_type.Properties.append(prop)

        sds_type = self.client.get_or_create_type(self.namespace_id, sds_type)
        if not sds_type:
            self.raise_error("init_type() ERROR: Failed to create type")
        self.types[type_id] = sds_type

        return True