コード例 #1
0
ファイル: kvstore.py プロジェクト: wlm328cs/openr
    def _run(self, client: OpenrCtrl.Client, key: str) -> None:
        area = self.get_area_id()
        publication = None
        if area is None:
            publication = client.getKvStoreKeyVals([key])
        else:
            publication = client.getKvStoreKeyValsArea([key], area)
        keyVals = publication.keyVals

        if key not in keyVals:
            print("Error: Key {} not found in KvStore.".format(key))
            sys.exit(1)

        # Get and modify the key
        val = keyVals.get(key)
        val.value = None
        val.ttl = 256  # set new ttl to 256ms (its decremented 1ms on every hop)
        val.ttlVersion += 1  # bump up ttl version

        print(keyVals)

        if area is None:
            client.setKvStoreKeyVals(openr_types.KeySetParams(keyVals))
        else:
            client.setKvStoreKeyVals(openr_types.KeySetParams(keyVals), area)

        print("Success: key {} will be erased soon from all KvStores.".format(
            key))
コード例 #2
0
ファイル: kvstore.py プロジェクト: schijioke-uche/openr
    def _run(
        self,
        client: OpenrCtrl.Client,
        key: str,
        value: Any,
        originator: str,
        version: Any,
        ttl: int,
    ) -> None:
        area = self.get_area_id()
        val = kv_store_types.Value()

        if version is None:
            # Retrieve existing Value from KvStore
            publication = None
            if area is None:
                publication = client.getKvStoreKeyVals([key])
            else:
                publication = client.getKvStoreKeyValsArea([key], area)
            if key in publication.keyVals:
                existing_val = publication.keyVals.get(key)
                print(
                    "Key {} found in KvStore w/ version {}. Overwriting with"
                    " higher version ...".format(key, existing_val.version)
                )
                version = existing_val.version + 1
            else:
                version = 1
        val.version = version

        val.originatorId = originator
        val.value = value
        val.ttl = ttl
        val.ttlVersion = 1

        # Advertise publication back to KvStore
        keyVals = {key: val}
        if area is None:
            client.setKvStoreKeyVals(kv_store_types.KeySetParams(keyVals))
        else:
            client.setKvStoreKeyVals(kv_store_types.KeySetParams(keyVals), area)
        print(
            "Success: Set key {} with version {} and ttl {} successfully"
            " in KvStore. This does not guarantee that value is updated"
            " in KvStore as old value can be persisted back".format(
                key,
                val.version,
                val.ttl if val.ttl != Consts.CONST_TTL_INF else "infinity",
            )
        )
コード例 #3
0
    def _run(self, client: OpenrCtrl.Client, key: str) -> None:
        publication = client.getKvStoreKeyVals([key])
        keyVals = publication.keyVals

        if key not in keyVals:
            print("Error: Key {} not found in KvStore.".format(key))
            sys.exit(1)

        # Get and modify the key
        val = keyVals.get(key)
        val.value = None
        val.ttl = 256  # set new ttl to 256ms (its decremented 1ms on every hop)
        val.ttlVersion += 1  # bump up ttl version

        print(keyVals)

        client.setKvStoreKeyVals(
            kv_store_types.KeySetParams(keyVals), kv_store_constants.kDefaultArea
        )

        print("Success: key {} will be erased soon from all KvStores.".format(key))