Example #1
0
def commit_project(project_id, message, author, changes):
    channel = grpc.insecure_channel(config.PROJECTS_SERVICES_ENDPOINT)
    stub = project_pb2_grpc.ProjectServicesStub(channel=channel)

    project = stub.Retrieve(project_pb2.ID(id=project_id))

    etcd = etcd3.client(host=config.ETCD_HOST, port=config.ETCD_PORT)

    # acquire lock
    with etcd.lock(project_id, ttl=1800) as lock:
        # copy data to repo_bucket
        minio_client = get_minio_client()
        for change in changes:
            key = os.path.relpath(change["path"],
                                  config.ILYDE_WORKING_DIR).replace('\\', '/')
            if change['action'] == "deleted":
                minio_client.remove_object(bucket_name=project.repo_bucket,
                                           object_name=key)
            else:
                file_type, _ = mimetypes.guess_type(change["path"])
                if file_type is None:
                    file_type = 'application/octet-stream'
                minio_client.fput_object(project.repo_bucket,
                                         key,
                                         change["path"],
                                         content_type=file_type)

        # create new revision
        payload = {'project': project_id, 'commit': message, 'author': author}
        response = stub.CreateRevision(project_pb2.Revision(**payload))
        return response
Example #2
0
def run():
    channel = grpc.insecure_channel('localhost:50051')
    stub = project_pb2_grpc.ProjectServicesStub(channel)

    try:
        payload = {
            'name': 'fashion-mnist',
            'description': 'Introduction to computer vision.',
            'visibility': 'PUBLIC',
            'template': "GENERIC",
            'owner': '1234-2344-1234-2345',
        }
        # response = stub.Create(service_pb2.Project(**payload))
        response = stub.SearchRevision(project_pb2.SearchRevisionRequest())
    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))
Example #3
0
def last_project_revision(project_id):
    channel = grpc.insecure_channel(config.PROJECTS_SERVICES_ENDPOINT)
    stub = project_pb2_grpc.ProjectServicesStub(channel=channel)

    query = {"project": project_id}

    response = stub.SearchRevision(
        project_pb2.SearchRevisionRequest(query=query))
    return response.data[0]
Example #4
0
 def test_search(self):
     logger.info("test search project")
     stub = project_pb2_grpc.ProjectServicesStub(self._channel)
     # TODO: create a function that create fake projects for search purpose
     # prepare a payload
     payload = {
         'page': 1,
         'limit': 1,
         'query': {
             'name': 'Iris Classification Context'
         }
     }
     response = stub.Search(project_pb2.SearchProjectRequest(**payload))
     self.assertTrue(response.total == 3)
     response = stub.Search(project_pb2.SearchProjectRequest(**payload))
     self.assertEqual(response.total, 3)
     self.assertEqual(len(response.projects), 1)
Example #5
0
def copy_project_files(project_id, files):
    channel = grpc.insecure_channel(config.PROJECTS_SERVICES_ENDPOINT)
    stub = project_pb2_grpc.ProjectServicesStub(channel=channel)

    project = stub.Retrieve(project_pb2.ID(id=project_id))

    # get minio client
    minio_client = get_minio_client()
    for file in files:
        destination = os.path.join(config.ILYDE_WORKING_DIR, file["name"])
        try:
            obj = minio_client.fget_object(bucket_name=project.repo_bucket,
                                           object_name=file["name"],
                                           file_path=destination,
                                           version_id=file["version"])
            # add modification time
            os.utime(destination, (time.mktime(
                time.localtime()), time.mktime(obj.last_modified)))
        except MinioError as e:
            pass
        except Exception as e:
            pass
Example #6
0
def retrieve_project_revision(revision_id):
    channel = grpc.insecure_channel(config.PROJECTS_SERVICES_ENDPOINT)
    stub = project_pb2_grpc.ProjectServicesStub(channel=channel)

    return stub.RetrieveRevision(project_pb2.ID(id=revision_id))
Example #7
0
def get_projects_services_stub():
    channel = grpc.insecure_channel(
        current_app.config.get("PROJECTS_SERVICES_ENDPOINT"))
    stub = project_pb2_grpc.ProjectServicesStub(channel=channel)
    return stub