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

/*
 * Please include the following imports to run this sample.
 *
 * 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;
 */

/** Create Tenant for scoping resources, e.g. companies and jobs */
public static void sampleCreateTenant(String projectId, String externalId) {
  try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
    // projectId = "Your Google Cloud Project ID";
    // externalId = "Your Unique Identifier for Tenant";
    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.printf("Name: %s\n", response.getName());
    System.out.printf("External ID: %s\n", response.getExternalId());
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

Node.js

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


const talent = require('@google-cloud/talent').v4beta1;

/** Create Tenant for scoping resources, e.g. companies and jobs */
function sampleCreateTenant(projectId, externalId) {
  const client = new talent.TenantServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const externalId = 'Your Unique Identifier for Tenant';
  const formattedParent = client.projectPath(projectId);
  const tenant = {
    externalId: externalId,
  };
  const request = {
    parent: formattedParent,
    tenant: tenant,
  };
  client.createTenant(request)
    .then(responses => {
      const response = responses[0];
      console.log(`Created Tenant`);
      console.log(`Name: ${response.name}`);
      console.log(`External ID: ${response.externalId}`);
    })
    .catch(err => {
      console.error(err);
    });
}

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_v4beta1
import six


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

    client = talent_v4beta1.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))


Ruby

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


# Create Tenant for scoping resources, e.g. companies and jobs
def sample_create_tenant(project_id, external_id)
  # Instantiate a client
  tenant_client = Google::Cloud::Talent::TenantService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # external_id = "Your Unique Identifier for Tenant"
  formatted_parent = tenant_client.class.project_path(project_id)
  tenant = { external_id: external_id }

  response = tenant_client.create_tenant(formatted_parent, tenant)
  puts "Created Tenant"
  puts "Name: #{response.name}"
  puts "External ID: #{response.external_id}"

end

Retrieve a tenant

Java

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

/*
 * Please include the following imports to run this sample.
 *
 * 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;
 */

/** Get Tenant by name */
public static void sampleGetTenant(String projectId, String tenantId) {
  try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
    // projectId = "Your Google Cloud Project ID";
    // tenantId = "Your Tenant ID";
    TenantName name = TenantName.of(projectId, tenantId);
    GetTenantRequest request = GetTenantRequest.newBuilder().setName(name.toString()).build();
    Tenant response = tenantServiceClient.getTenant(request);
    System.out.printf("Name: %s\n", response.getName());
    System.out.printf("External ID: %s\n", response.getExternalId());
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

Node.js

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


const talent = require('@google-cloud/talent').v4beta1;

/** Get Tenant by name */
function sampleGetTenant(projectId, tenantId) {
  const client = new talent.TenantServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID';
  const formattedName = client.tenantPath(projectId, tenantId);
  client.getTenant({name: formattedName})
    .then(responses => {
      const response = responses[0];
      console.log(`Name: ${response.name}`);
      console.log(`External ID: ${response.externalId}`);
    })
    .catch(err => {
      console.error(err);
    });
}

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_v4beta1
import six


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

    client = talent_v4beta1.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.


# Get Tenant by name
def sample_get_tenant(project_id, tenant_id)
  # Instantiate a client
  tenant_client = Google::Cloud::Talent::TenantService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # tenant_id = "Your Tenant ID"
  formatted_name = tenant_client.class.tenant_path(project_id, tenant_id)

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

end

List tenants

Java

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

/*
 * Please include the following imports to run this sample.
 *
 * 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;
 */

/** List Tenants */
public static void sampleListTenants(String projectId) {
  try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
    // projectId = "Your Google Cloud Project ID";
    ProjectName parent = ProjectName.of(projectId);
    ListTenantsRequest request =
        ListTenantsRequest.newBuilder().setParent(parent.toString()).build();
    for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) {
      System.out.printf("Tenant Name: %s\n", responseItem.getName());
      System.out.printf("External ID: %s\n", responseItem.getExternalId());
    }
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

Node.js

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


const talent = require('@google-cloud/talent').v4beta1;

/** List Tenants */
function sampleListTenants(projectId) {
  const client = new talent.TenantServiceClient();
  // Iterate over all elements.
  // const projectId = 'Your Google Cloud Project ID';
  const formattedParent = client.projectPath(projectId);

  client.listTenants({parent: formattedParent})
    .then(responses => {
      const resources = responses[0];
      for (const resource of resources) {
        console.log(`Tenant Name: ${resource.name}`);
        console.log(`External ID: ${resource.externalId}`);
      }
    })
    .catch(err => {
      console.error(err);
    });
}

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_v4beta1
import six


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

    client = talent_v4beta1.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.


# List Tenants
def sample_list_tenants(project_id)
  # Instantiate a client
  tenant_client = Google::Cloud::Talent::TenantService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  formatted_parent = tenant_client.class.project_path(project_id)

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

end

Delete a tenant

Java

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

/*
 * Please include the following imports to run this sample.
 *
 * import com.google.cloud.talent.v4beta1.DeleteTenantRequest;
 * import com.google.cloud.talent.v4beta1.TenantName;
 * import com.google.cloud.talent.v4beta1.TenantServiceClient;
 */

/** Delete Tenant */
public static void sampleDeleteTenant(String projectId, String tenantId) {
  try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
    // projectId = "Your Google Cloud Project ID";
    // tenantId = "Your Tenant ID)";
    TenantName name = TenantName.of(projectId, tenantId);
    DeleteTenantRequest request =
        DeleteTenantRequest.newBuilder().setName(name.toString()).build();
    tenantServiceClient.deleteTenant(request);
    System.out.println("Deleted Tenant.");
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);
  }
}

Node.js

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


const talent = require('@google-cloud/talent').v4beta1;

/** Delete Tenant */
function sampleDeleteTenant(projectId, tenantId) {
  const client = new talent.TenantServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID)';
  const formattedName = client.tenantPath(projectId, tenantId);
  client.deleteTenant({name: formattedName}).catch(err => {
    console.error(err);
  });
  console.log(`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_v4beta1
import six


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

    client = talent_v4beta1.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.


# Delete Tenant
def sample_delete_tenant(project_id, tenant_id)
  # Instantiate a client
  tenant_client = Google::Cloud::Talent::TenantService.new version: :v4beta1

  # project_id = "Your Google Cloud Project ID"
  # tenant_id = "Your Tenant ID)"
  formatted_name = tenant_client.class.tenant_path(project_id, tenant_id)

  tenant_client.delete_tenant(formatted_name)

  puts "Deleted Tenant."

end

Czy ta strona była pomocna? Podziel się z nami swoją opinią:

Wyślij opinię na temat...

Job Search documentation