Ejemplo n.º 1
0
def create_dataset_version(dataset_id, related_bucket, author):
    channel = grpc.insecure_channel(config.DATASETS_SERVICES_ENDPOINT)
    stub = dataset_pb2_grpc.DatasetServicesStub(channel=channel)
    payload = {
        'dataset': dataset_id,
        'related_bucket': related_bucket,
        "author": author
    }
    stub.CreateVersion(dataset_pb2.Version(**payload))
Ejemplo n.º 2
0
def search_dataset_version(dataset_id, version_name):
    channel = grpc.insecure_channel(config.DATASETS_SERVICES_ENDPOINT)
    stub = dataset_pb2_grpc.DatasetServicesStub(channel=channel)
    if version_name != "latest":
        query = {"name": version_name, "dataset": dataset_id}
    else:
        query = {"dataset": dataset_id}

    response = stub.SearchVersions(
        dataset_pb2.SearchVersionRequest(query=query))
    return response.data[0] if response.data else None
Ejemplo n.º 3
0
    def test_create_dataset(self):
        logger.info("test create dataset")
        stub = dataset_pb2_grpc.DatasetServicesStub(self._channel)
        # prepare a payload
        payload = {
            'name': 'fashion-mnist-data',
            'description': 'Dataset di fashion 28x28.',
            'scope': "Global"
        }

        response = stub.CreateDataset(dataset_pb2.Dataset(**payload))
        self.assertTrue(response.id)
        self.assertTrue(response.create_at)
        self.assertEqual(response.name, payload['name'])
Ejemplo n.º 4
0
    def test_retrieve_dataset(self):
        logger.info("test retrieve dataset")
        stub = dataset_pb2_grpc.DatasetServicesStub(self._channel)
        # prepare a payload
        payload = {
            'name': 'fashion-mnist-data',
            'description': 'Dataset di fashion 28x28.',
            'scope': "Global"
        }

        dataset = stub.CreateDataset(dataset_pb2.Dataset(**payload))
        # verify if we can retrieve dataset
        response = stub.RetrieveDataset(dataset_pb2.ID(id=dataset.id))
        self.assertEqual(response.id, dataset.id)
        self.assertEqual(response.name, dataset.name)
        # verify raise of error when doesn't exists
        with self.assertRaises(grpc.RpcError) as cm:
            stub.RetrieveDataset(dataset_pb2.ID(id="my-id"))
Ejemplo n.º 5
0
        response = stub.SearchVersions(dataset_pb2.SearchVersionRequest())
    except grpc.RpcError as e:
        # ouch!
        # lets print the gRPC error message
        # which is "Length of `Name` cannot be more than 10 characters"
        print(e.details(), e)
        # lets access the error code, which is `INVALID_ARGUMENT`
        # `type` of `status_code` is `grpc.StatusCode`
        status_code = e.code()
        # should print `INVALID_ARGUMENT`
        print(status_code.name)
        # should print `(3, 'invalid argument')`
        print(status_code.value)
        # want to do some specific action based on the error?
        if grpc.StatusCode.INVALID_ARGUMENT == status_code:
            # do your stuff here
            pass
    else:
        print(
            json_format.MessageToJson(
                response,
                preserving_proto_field_name=True,
                including_default_value_fields=True,
            ))


if __name__ == '__main__':
    channel = grpc.insecure_channel('localhost:50051')
    stub = dataset_pb2_grpc.DatasetServicesStub(channel)
    run()
Ejemplo n.º 6
0
def retrieve_dataset(dataset_id):
    channel = grpc.insecure_channel(config.DATASETS_SERVICES_ENDPOINT)
    stub = dataset_pb2_grpc.DatasetServicesStub(channel=channel)
    return stub.RetrieveDataset(dataset_pb2.ID(id=dataset_id))
Ejemplo n.º 7
0
def create_dataset_bucket():
    channel = grpc.insecure_channel(config.DATASETS_SERVICES_ENDPOINT)
    stub = dataset_pb2_grpc.DatasetServicesStub(channel=channel)

    bucket = stub.CreateBucket(dataset_pb2.Bucket())
    return bucket.name
Ejemplo n.º 8
0
def get_datasets_services_stub():
    channel = grpc.insecure_channel(
        current_app.config.get('DATASETS_SERVICES_ENDPOINT'))
    stub = dataset_pb2_grpc.DatasetServicesStub(channel=channel)
    return stub