Skip to content

2.8 Searching data centers

jwebs1 edited this page Jul 6, 2015 · 4 revisions

Searching data centers

This section overviews data center search features available in the SDK. Note that in all examples, dataCenterService refers to the new ClcSdk().dataCenterService() variable.

Searching with a filter

It is possible to find data centers using DataCenterFilter, where you can specify any search criteria, like this:

List<DataCenterMetadata> results = 
    dataCenterService
        .find(new DataCenterFilter()
            .dataCenters(dataCenterRef)
            .id("va1", "ca1")
            .nameContains("FrankFurt")
            .where(d -> d.getGroup().getName().equals("groupName"))
        );

Here is the list of available search criteria:

  • Data center references (dataCenters(dataCenterRef))
  • Data center IDs (id("va1", "ca1")
  • Data center name, ignoring cases (nameContains("FrankFurt"))
  • A predicate (where(d -> d.getGroup().getName().equals("groupName"))

AND/OR conditions can also be applied to DataCenterFilter:

  • dataCenterFilter1.and(dataCenterFilter2)
  • dataCenterFilter1.or(dataCenterFilter2)

Searching by a reference

You can search for a specific data center by its DataCenter reference. The list of predefined data center references can be found at: com.centurylink.cloud.sdk.common.management.services.domain.datacenters.refs.DataCenter.

Here is a sample search query:

DataCenterMetadata dataCenter = dataCenterService.findByRef(DataCenter.DE_FRANKFURT);

There are two types of DataCenter references—ID (DataCenterByIdRef) and name (DataCenterByNameRef).

DataCenterMetadata dataCenterById = dataCenterService.findByRef(new DataCenterByIdRef("de1"));
DataCenterMetadata dataCenterByName = dataCenterService.findByRef(new DataCenterByNameRef("FrankFurt"));

Find all data centers

To find all available data centers, use:

List<DataCenterMetadata> dataCenters = dataCenterService.findAll();