Tenant basics

Tenants are entities that own any jobs and companies objects assigned to them. They create a middle layer of organization between a Google Cloud Platform project and your uploaded data. Tenants allow you to isolate different groupings of your data without the need for multiple projects by preventing any data from being shared across tenancy barriers. Multi-tenancy is useful in situations where you may have more than one customer and don't want to share data between them, but would like to maintain a single GCP project for internal billing and reporting. For example:

  • Job site providers building job sites for organizations with multiple subsidiary companies.
  • Hiring agencies building applicant tracking systems for multiple businesses.

Each Google Cloud Platform project is assigned a tenant_id for a single default tenant. Optionally, you can change the default by creating more than one tenant within a given project.

Tenants are fully isolated from one another. All APIs ask for only a single tenant to prevent data being queried across multiple tenants in a single API call. Machine learning (ML) similarly treats tenants as discrete units and does not cross tenancy barriers. A project can support as many tenants as required.

Default tenants

In Job Search v4beta1 and newer, a Tenant entity is required. All projects are assigned a tenant_id for a single default tenant. If you don't want to use multiple tenants, you can either:

  1. Use your project's default tenant (Recommended). You don't need to reference the tenant specifically in order to do this. You can use the format projects/{project_id}/jobs/{job_id} and the Cloud Talent Solution backend will assume that you're using the default tenant.

  2. Create a single tenant and use it in place of the default tenant. If you create your own tenant, you need to reference it: projects/{project_id}/tenants/{tenant_id}/jobs/{job_id}.

The default tenant_id is unique to each project and is never overwritten or replaced if you create additional tenants. You cannot call CRUD methods on the default tenant.

Created tenants (optional)

Creating your own tenants is optional. Each Job Search project is assigned a default tenant by the CTS backend. If you do not want to use multi-tenancy to separate subdivisions of your data, we recommend that you use the default tenant.

Create a tenant

You are required to create a unique externalId value and assign it to the new tenant. The call then returns a unique name assigned by our backend system, also assigned to that tenant. Be sure to record and store both the name and externalId values, as they are used to update/delete/reference.

The code sample below creates a new tenant:

Java


import com.google.cloud.talent.v4beta1.CreateTenantRequest;
import com.google.cloud.talent.v4beta1.ProjectName;
import com.google.cloud.talent.v4beta1.Tenant;
import com.google.cloud.talent.v4beta1.TenantServiceClient;
import java.io.IOException;

public class JobSearchCreateTenant {

  public static void createTenant() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String externalId = "your-external-id";
    createTenant(projectId, externalId);
  }

  // Create Tenant for scoping resources, e.g. companies and jobs.
  public static void createTenant(String projectId, String externalId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
      ProjectName parent = ProjectName.of(projectId);
      Tenant tenant = Tenant.newBuilder().setExternalId(externalId).build();

      CreateTenantRequest request =
          CreateTenantRequest.newBuilder().setParent(parent.toString()).setTenant(tenant).build();

      Tenant response = tenantServiceClient.createTenant(request);
      System.out.println("Created Tenant");
      System.out.format("Name: %s%n", response.getName());
      System.out.format("External ID: %s%n", response.getExternalId());
    }
  }
}

PHP

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\TenantServiceClient;
use Google\Cloud\Talent\V4beta1\Tenant;

/** Create Tenant for scoping resources, e.g. companies and jobs */
function sampleCreateTenant($projectId, $externalId)
{

    $tenantServiceClient = new TenantServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $externalId = 'Your Unique Identifier for Tenant';
    $formattedParent = $tenantServiceClient->projectName($projectId);
    $tenant = new Tenant();
    $tenant->setExternalId($externalId);

    try {
        $response = $tenantServiceClient->createTenant($formattedParent, $tenant);
        printf('Created Tenant'.PHP_EOL);
        printf('Name: %s'.PHP_EOL, $response->getName());
        printf('External ID: %s'.PHP_EOL, $response->getExternalId());
    } finally {
        $tenantServiceClient->close();
    }

}

Python

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


from google.cloud import talent
import six


def create_tenant(project_id, external_id):
    """Create Tenant for scoping resources, e.g. companies and jobs"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # external_id = 'Your Unique Identifier for Tenant'

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode("utf-8")
    if isinstance(external_id, six.binary_type):
        external_id = external_id.decode("utf-8")
    parent = client.project_path(project_id)
    tenant = {"external_id": external_id}

    response = client.create_tenant(parent, tenant)
    print("Created Tenant")
    print("Name: {}".format(response.name))
    print("External ID: {}".format(response.external_id))
    return response.name

Ruby

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require "google/cloud/talent"

# Instantiate a client
tenant_service = Google::Cloud::Talent.tenant_service

# project_id = "Your Google Cloud Project ID"
# external_id = "Your Unique Identifier for Tenant"
parent = tenant_service.project_path project: project_id
tenant = { external_id: external_id }

response = tenant_service.create_tenant parent: parent, tenant: tenant
puts "Created Tenant"
puts "Name: #{response.name}"
puts "External ID: #{response.external_id}"

C#

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

public static object CreateTenant(string projectId, string externalId)
{
    TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
    Tenant tenant = new Tenant
    {
        ExternalId = externalId,
    };
    ProjectName parent = new ProjectName(projectId);
    CreateTenantRequest request = new CreateTenantRequest
    {
        ParentAsProjectName = parent,
        Tenant = tenant
    };
    Tenant response = tenantServiceClient.CreateTenant(request);

    Console.WriteLine($"Created Tenant.");
    Console.WriteLine($"Name: {response.Name}");
    Console.WriteLine($"External ID: {response.ExternalId}");
    return 0;
}

Retrieve a tenant

Java

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


import com.google.cloud.talent.v4beta1.GetTenantRequest;
import com.google.cloud.talent.v4beta1.Tenant;
import com.google.cloud.talent.v4beta1.TenantName;
import com.google.cloud.talent.v4beta1.TenantServiceClient;
import java.io.IOException;

public class JobSearchGetTenant {

  public static void getTenant() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    getTenant(projectId, tenantId);
  }

  // Get Tenant by name.
  public static void getTenant(String projectId, String tenantId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
      TenantName name = TenantName.of(projectId, tenantId);

      GetTenantRequest request = GetTenantRequest.newBuilder().setName(name.toString()).build();

      Tenant response = tenantServiceClient.getTenant(request);
      System.out.format("Name: %s%n", response.getName());
      System.out.format("External ID: %s%n", response.getExternalId());
    }
  }
}

PHP

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\TenantServiceClient;

/** Get Tenant by name */
function sampleGetTenant($projectId, $tenantId)
{

    $tenantServiceClient = new TenantServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID';
    $formattedName = $tenantServiceClient->tenantName($projectId, $tenantId);

    try {
        $response = $tenantServiceClient->getTenant($formattedName);
        printf('Name: %s'.PHP_EOL, $response->getName());
        printf('External ID: %s'.PHP_EOL, $response->getExternalId());
    } finally {
        $tenantServiceClient->close();
    }

}

Python

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


from google.cloud import talent
import six


def get_tenant(project_id, tenant_id):
    """Get Tenant by name"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID'

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, six.binary_type):
        tenant_id = tenant_id.decode("utf-8")
    name = client.tenant_path(project_id, tenant_id)

    response = client.get_tenant(name)
    print("Name: {}".format(response.name))
    print("External ID: {}".format(response.external_id))

Ruby

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require "google/cloud/talent"

# Instantiate a client
tenant_service = Google::Cloud::Talent.tenant_service

# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID"
formatted_name = tenant_service.tenant_path project: project_id, tenant: tenant_id

response = tenant_service.get_tenant name: formatted_name
puts "Name: #{response.name}"
puts "External ID: #{response.external_id}"

C#

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

public static object GetTenant(string projectId, string tenantId)
{
    TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
    TenantName name = TenantName.FromProjectTenant(projectId, tenantId);
    GetTenantRequest request = new GetTenantRequest
    {
        TenantName = name
    };
    Tenant response = tenantServiceClient.GetTenant(request);
    Console.WriteLine($"Name: {response.Name}");
    Console.WriteLine($"External ID: {response.ExternalId}");
    return 0;
}

List tenants

Java

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


import com.google.cloud.talent.v4beta1.ListTenantsRequest;
import com.google.cloud.talent.v4beta1.ProjectName;
import com.google.cloud.talent.v4beta1.Tenant;
import com.google.cloud.talent.v4beta1.TenantServiceClient;
import java.io.IOException;

public class JobSearchListTenants {

  public static void listTenants() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    listTenants(projectId);
  }

  // List Tenants.
  public static void listTenants(String projectId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
      ProjectName parent = ProjectName.of(projectId);

      ListTenantsRequest request =
          ListTenantsRequest.newBuilder().setParent(parent.toString()).build();

      for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) {
        System.out.format("Tenant Name: %s%n", responseItem.getName());
        System.out.format("External ID: %s%n", responseItem.getExternalId());
      }
    }
  }
}

PHP

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\TenantServiceClient;

/** List Tenants */
function sampleListTenants($projectId)
{

    $tenantServiceClient = new TenantServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    $formattedParent = $tenantServiceClient->projectName($projectId);

    try {
        // Iterate through all elements
        $pagedResponse = $tenantServiceClient->listTenants($formattedParent);
        foreach ($pagedResponse->iterateAllElements() as $responseItem) {
            printf('Tenant Name: %s'.PHP_EOL, $responseItem->getName());
            printf('External ID: %s'.PHP_EOL, $responseItem->getExternalId());
        }
    } finally {
        $tenantServiceClient->close();
    }

}

Python

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


from google.cloud import talent
import six


def list_tenants(project_id):
    """List Tenants"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode("utf-8")
    parent = client.project_path(project_id)

    # Iterate over all results
    for response_item in client.list_tenants(parent):
        print("Tenant Name: {}".format(response_item.name))
        print("External ID: {}".format(response_item.external_id))

Ruby

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require "google/cloud/talent"

# Instantiate a client
tenant_service = Google::Cloud::Talent.tenant_service

# project_id = "Your Google Cloud Project ID"
formatted_parent = tenant_service.project_path project: project_id

# Iterate over all results.
tenant_service.list_tenants(parent: formatted_parent).each do |element|
  puts "Tenant Name: #{element.name}"
  puts "External ID: #{element.external_id}"
end

C#

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

public static object ListTenants(string projectId)
{
    TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
    ProjectName parent = new ProjectName(projectId);
    ListTenantsRequest request = new ListTenantsRequest
    {
        ParentAsProjectName = parent
    };
    var tenants = tenantServiceClient.ListTenants(request);
    foreach (var tenant in tenants)
    {
        Console.WriteLine($"Tenant Name: {tenant.Name}");
        Console.WriteLine($"External ID: {tenant.ExternalId}");
    }
    return 0;
}

Delete a tenant

Java

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


import com.google.cloud.talent.v4beta1.DeleteTenantRequest;
import com.google.cloud.talent.v4beta1.TenantName;
import com.google.cloud.talent.v4beta1.TenantServiceClient;
import java.io.IOException;

public class JobSearchDeleteTenant {

  public static void deleteTenant() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String tenantId = "your-tenant-id";
    deleteTenant(projectId, tenantId);
  }

  // Delete Tenant.
  public static void deleteTenant(String projectId, String tenantId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
      TenantName name = TenantName.of(projectId, tenantId);

      DeleteTenantRequest request =
          DeleteTenantRequest.newBuilder().setName(name.toString()).build();

      tenantServiceClient.deleteTenant(request);
      System.out.println("Deleted Tenant.");
    }
  }
}

PHP

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Talent\V4beta1\TenantServiceClient;

/** Delete Tenant */
function sampleDeleteTenant($projectId, $tenantId)
{

    $tenantServiceClient = new TenantServiceClient();

    // $projectId = 'Your Google Cloud Project ID';
    // $tenantId = 'Your Tenant ID)';
    $formattedName = $tenantServiceClient->tenantName($projectId, $tenantId);

    try {
        $tenantServiceClient->deleteTenant($formattedName);
        printf('Deleted Tenant.'.PHP_EOL);
    } finally {
        $tenantServiceClient->close();
    }

}

Python

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.


from google.cloud import talent
import six


def delete_tenant(project_id, tenant_id):
    """Delete Tenant"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID)'

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode("utf-8")
    if isinstance(tenant_id, six.binary_type):
        tenant_id = tenant_id.decode("utf-8")
    name = client.tenant_path(project_id, tenant_id)

    client.delete_tenant(name)
    print("Deleted Tenant.")

Ruby

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

require "google/cloud/talent"

# Instantiate a client
tenant_service = Google::Cloud::Talent.tenant_service

# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID)"
formatted_name = tenant_service.tenant_path project: project_id, tenant: tenant_id

tenant_service.delete_tenant name: formatted_name

puts "Deleted Tenant."

C#

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

public static object DeleteTenant(string projectId, string tenantId)
{
    TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
    TenantName tenantName = TenantName.FromProjectTenant(projectId, tenantId);
    DeleteTenantRequest request = new DeleteTenantRequest
    {
        TenantName = tenantName
    };
    tenantServiceClient.DeleteTenant(request);
    Console.WriteLine($"Deleted Tenant.");
    return 0;
}