-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathLimitsExample.java
More file actions
84 lines (73 loc) · 3.89 KB
/
LimitsExample.java
File metadata and controls
84 lines (73 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
*/
import com.oracle.bmc.ConfigFileReader;
import com.oracle.bmc.Region;
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
import com.oracle.bmc.limits.Limits;
import com.oracle.bmc.limits.LimitsClient;
import com.oracle.bmc.limits.model.LimitDefinitionSummary;
import com.oracle.bmc.limits.requests.GetResourceAvailabilityRequest;
import com.oracle.bmc.limits.responses.GetResourceAvailabilityResponse;
import com.oracle.bmc.limits.requests.ListLimitDefinitionsRequest;
import com.oracle.bmc.limits.responses.ListLimitDefinitionsResponse;
/**
* This class provides an example of how you can use the API to interact with the resource limits of
* a specific resource type. You will be able to find the following information:
*
* <ul>
* <li>Name
* <li>Description
* <li>Availability
* <li>Usage
* </ul>
*/
public class LimitsExample {
private static final String SERVICE_NAME = "limits";
private static final String LIMIT_NAME = "policy-count";
public static void main(String[] args) throws Exception {
String configurationFilePath = "~/.oci/config";
String profile = "DEFAULT";
// Configuring the AuthenticationDetailsProvider. It's assuming there is a default OCI
// config file
// "~/.oci/config", and a profile in that config with the name "DEFAULT". Make changes to
// the following
// line if needed and use ConfigFileReader.parse(configurationFilePath, profile);
final ConfigFileReader.ConfigFile configFile = ConfigFileReader.parseDefault();
final AuthenticationDetailsProvider provider =
new ConfigFileAuthenticationDetailsProvider(configFile);
Limits client = LimitsClient.builder().region(Region.US_PHOENIX_1).build(provider);
// For a given compartmentId and service name it returns the name and description of the
// limit
ListLimitDefinitionsRequest listLimitDefinitionsRequest =
ListLimitDefinitionsRequest.builder()
.compartmentId(provider.getTenantId())
.serviceName(SERVICE_NAME)
.build();
ListLimitDefinitionsResponse listLimitDefinitionsResponse =
client.listLimitDefinitions(listLimitDefinitionsRequest);
for (LimitDefinitionSummary summary : listLimitDefinitionsResponse.getItems()) {
System.out.println("Limit Name: " + summary.getName());
System.out.println("Limit Description: " + summary.getDescription());
}
// For a given compartmentId, service name and resource limit name, it returns
// the number of available resources associated with the given limit and
// the usage in the selected compartment for the given limit
GetResourceAvailabilityRequest getResourceAvailabilityRequest =
GetResourceAvailabilityRequest.builder()
.compartmentId(provider.getTenantId())
.serviceName(SERVICE_NAME)
.limitName(LIMIT_NAME)
.build();
GetResourceAvailabilityResponse resourceAvailabilityResponse =
client.getResourceAvailability(getResourceAvailabilityRequest);
System.out.println(
"Availability: "
+ resourceAvailabilityResponse.getResourceAvailability().getAvailable());
System.out.println(
"Usage: " + resourceAvailabilityResponse.getResourceAvailability().getUsed());
client.close();
}
}