Пример #1
0
    def clone(self, to_namespace, to_name):
        """Clone this workspace.

        Args:
            to_namespace (str): Target workspace namespace
            to_name (str): Target workspace name
        """
        r = fapi.clone_workspace(self.namespace, self.name,
                                 to_namespace, to_name, self.api_url)
        fapi._check_response_code(r, 201)
        return Workspace(to_namespace, to_name, self.api_url)
Пример #2
0
    def test_clone_workspace(self):
        """Test clone_workspace()."""
        temp_space = getuser() + '_FISS_TEST_CLONE'
        r = fapi.unlock_workspace(self.project, temp_space)
        r = fapi.delete_workspace(self.project, temp_space)
        r = fapi.clone_workspace(self.project, self.workspace, self.project,
                                 temp_space)
        print(r.status_code, r.content)
        self.assertEqual(r.status_code, 201)

        # Compare new workspace and old workspace
        # Cleanup, Delete workspace
        r = fapi.delete_workspace(self.project, temp_space)
        print(r.status_code, r.content)
        self.assertIn(r.status_code, [200, 202])
Пример #3
0
def clone_workspace(src_namespace,
                    src_workspace,
                    dest_namespace,
                    dest_workspace,
                    auth_domains,
                    copyFilesWithPrefix=None):
    """Clone a Terra workspace."""

    workspace = fapi.clone_workspace(src_namespace, src_workspace,
                                     dest_namespace, dest_workspace,
                                     auth_domains, copyFilesWithPrefix)
    workspace_json = workspace.json()

    # workspace clone fails
    if workspace.status_code != 201:
        print("Workspace clone failed. Please see below for full error.")
        print(workspace_json)
        return False, workspace_json

    print(f"Cloned workspace: {dest_namespace}/{dest_workspace}")
    return True, workspace_json
Пример #4
0
def hard_copy(original_workspace,
              original_project,
              new_workspace,
              new_project,
              set_auth_domain=None):
    # try:
    # check for auth_domain info
    if set_auth_domain is None:
        response = fapi.get_workspace(namespace=original_project,
                                      workspace=original_workspace)
        if response.status_code not in [200]:
            raise ferrors.FireCloudServerError(response.status_code,
                                               response.content)
        authorization_domain = response.json(
        )['workspace']['authorizationDomain']
        if len(authorization_domain) > 0:
            authorization_domain = authorization_domain[0]['membersGroupName']
    else:
        authorization_domain = set_auth_domain

    print(f'Setting authorization domain to {authorization_domain}')

    # clone the workspace
    response = fapi.clone_workspace(from_namespace=original_project,
                                    from_workspace=original_workspace,
                                    to_namespace=new_project,
                                    to_workspace=new_workspace,
                                    authorizationDomain=authorization_domain)
    if response.status_code in [409]:
        print(f'\nNOTE: {new_project}/{new_workspace} already exists!')
        return 'already exists'
    elif response.status_code not in [201]:
        raise ferrors.FireCloudServerError(response.status_code,
                                           response.content)

    # get bucket info for original and new workspace
    original_bucket = fapi.get_workspace(
        original_project, original_workspace).json()['workspace']['bucketName']
    new_bucket = fapi.get_workspace(
        new_project, new_workspace).json()['workspace']['bucketName']

    # copy bucket over
    bucket_files = run_subprocess(
        ['gsutil', 'ls', 'gs://' + original_bucket + '/'],
        'Error listing bucket contents')
    if len(bucket_files) > 0:
        gsutil_args = [
            'gsutil', '-m', 'rsync', '-r', 'gs://' + original_bucket,
            'gs://' + new_bucket
        ]
        bucket_files = run_subprocess(
            gsutil_args, 'Error copying over original bucket to clone bucket')

    # update data references
    update_attributes(new_workspace,
                      new_project,
                      replace_this=original_bucket,
                      with_this=new_bucket)
    update_entities(new_workspace,
                    new_project,
                    replace_this=original_bucket,
                    with_this=new_bucket)
    update_notebooks(new_workspace,
                     new_project,
                     replace_this=original_bucket,
                     with_this=new_bucket)

    # done
    print(
        f'\nFinished copying {original_project}/{original_workspace} to {new_project}/{new_workspace}.\nCheck it out at https://app.terra.bio/#workspaces/{new_project}/{new_workspace}'
    )

    return 'copy successful'