예제 #1
0
    def disconnect(self, namespace, delete=False):
        ## \brief Delete subscription by namespace
        # \param entity name
        # \param flag to indicate if the subscription must be deleted locally (False by default)
        if namespace in self.subscriptions:
            deleteContext(namespace, True)
            subscription = self.subscriptions[namespace]
            subscriptionId = subscription["id"]
            Log("INFO", "\nDisconnecting Context Broker subscription {}".format(subscriptionId))
            url = "http://{}:{}/NGSI10/unsubscribeContext".format(DATA_CONTEXTBROKER["ADDRESS"], DATA_CONTEXTBROKER["PORT"])
            disconnect_json = json.dumps({
                "subscriptionId": subscriptionId
            })
            response_body = self._sendRequest(url, disconnect_json)
            if response_body is not None:
                if int(response_body["statusCode"]["code"]) >= 400:
                    Log("ERROR", "Error Disconnecting from Context Broker (subscription: {}):".format(subscriptionId))
                    Log("ERROR", response_body["statusCode"]["reasonPhrase"])
                    Log("INFO", "\n")
                else:
                    Log("INFO", "Disconnected subscription {} from Context Broker ".format(subscriptionId))

            Log("INFO", "Deleting entity")
            self.deleteEntity(subscription["namespace"], subscription["data_type"])
            Log("INFO", "\n")
            if delete:
                del self.subscriptions[namespace]
예제 #2
0
    def deleteEntity(self, namespace, data_type, removeContext=True):
        ## \brief Delete entity from context broker
        # \param entity name
        # \param entity type
        Log("INFO", "DELETING: ", namespace, data_type)
        operation_json = json.dumps({
            "contextElements": [
                {
                    "type": data_type,
                    "isPattern": "false",
                    "id": namespace
                }
            ],
            "updateAction": "DELETE"
        })
        url = "http://{}:{}/NGSI10/updateContext".format(DATA_CONTEXTBROKER["ADDRESS"], DATA_CONTEXTBROKER["PORT"])
        response_body = self._sendRequest(url, operation_json)
        if response_body is not None:
            if "errorCode" in response_body:
                Log("ERROR", "Error deleting entity")
                Log("ERROR", response_body["errorCode"]["details"])
            elif "orionError" in response_body:
                Log("ERROR", "Error deleting entity")
                Log("ERROR", response_body["orionError"]["details"])
            else:
                Log("INFO", "Deleted entity " + namespace)

        if removeContext:
            deleteContext(namespace, True)
예제 #3
0
    def deleteEntity(self, namespace, data_type, removeContext=True):
        ## \brief Delete entity from context broker
        # \param entity name
        # \param entity type
        Log("INFO", "DELETING: ", namespace, data_type)
        operation_json = json.dumps({
            "contextElements": [{
                "type": data_type,
                "isPattern": "false",
                "id": namespace
            }],
            "updateAction":
            "DELETE"
        })
        url = "http://{}:{}/NGSI10/updateContext".format(
            DATA_CONTEXTBROKER["ADDRESS"], DATA_CONTEXTBROKER["PORT"])
        response_body = self._sendRequest(url, operation_json)
        if response_body is not None:
            if "errorCode" in response_body:
                Log("ERROR", "Error deleting entity")
                Log("ERROR", response_body["errorCode"]["details"])
            elif "orionError" in response_body:
                Log("ERROR", "Error deleting entity")
                Log("ERROR", response_body["orionError"]["details"])
            else:
                Log("INFO", "Deleted entity " + namespace)

        if removeContext:
            deleteContext(namespace, True)
예제 #4
0
    def disconnect(self, namespace, delete=False):
        ## \brief Delete subscription by namespace
        # \param entity name
        # \param flag to indicate if the subscription must be deleted locally (False by default)
        if namespace in self.subscriptions:
            deleteContext(namespace, True)
            subscription = self.subscriptions[namespace]
            subscriptionId = subscription["id"]
            Log(
                "INFO",
                "\nDisconnecting Context Broker subscription {}".format(
                    subscriptionId))
            url = "http://{}:{}/NGSI10/unsubscribeContext".format(
                DATA_CONTEXTBROKER["ADDRESS"], DATA_CONTEXTBROKER["PORT"])
            disconnect_json = json.dumps({"subscriptionId": subscriptionId})
            response_body = self._sendRequest(url, disconnect_json)
            if response_body is not None:
                if int(response_body["statusCode"]["code"]) >= 400:
                    Log(
                        "ERROR",
                        "Error Disconnecting from Context Broker (subscription: {}):"
                        .format(subscriptionId))
                    Log("ERROR", response_body["statusCode"]["reasonPhrase"])
                    Log("INFO", "\n")
                else:
                    Log(
                        "INFO",
                        "Disconnected subscription {} from Context Broker ".
                        format(subscriptionId))

            Log("INFO", "Deleting entity")
            self.deleteEntity(subscription["namespace"],
                              subscription["data_type"])
            Log("INFO", "\n")
            if delete:
                del self.subscriptions[namespace]