forked from oracle/oci-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetWorkRequestExample.java
More file actions
108 lines (86 loc) · 4.65 KB
/
GetWorkRequestExample.java
File metadata and controls
108 lines (86 loc) · 4.65 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Copyright (c) 2016, 2021, 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.auth.AuthenticationDetailsProvider;
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
import com.oracle.bmc.workrequests.WorkRequestClient;
import com.oracle.bmc.workrequests.requests.GetWorkRequestRequest;
import com.oracle.bmc.workrequests.requests.ListWorkRequestErrorsRequest;
import com.oracle.bmc.workrequests.requests.ListWorkRequestLogsRequest;
import com.oracle.bmc.workrequests.responses.GetWorkRequestResponse;
import com.oracle.bmc.workrequests.responses.ListWorkRequestErrorsResponse;
import com.oracle.bmc.workrequests.responses.ListWorkRequestLogsResponse;
import java.io.IOException;
/**
* This class provides an example of using the APIs to get information about a Work Request, looked up by the Work
* Request ID. The following examples are given:
*
* <ul>
* <li>getWorkRequest - Get information about a Work Request</li>
* <li>listWorkRequestErrors - List errors related to a Work Request</li>
* <li>listWorkRequestLogs - List logs related to a Work Request</li>
* </ul>
*/
public class GetWorkRequestExample {
private static final String CONFIG_LOCATION = "~/.oci/config";
private static final String CONFIG_PROFILE_DEFAULT = "DEFAULT";
/**
* The entry point for the example.
*
* @param args Arguments to provide to the example. The following arguments are expected:
* <ul>
* <li>The OCID of the Work Request for which to request information</li>
* </ul>
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
throw new IllegalArgumentException(
"This example expects the Work Request OCID as an argument.");
}
String workRequestId = args[0];
try (WorkRequestClient client = getWorkRequestClient()) {
getWorkRequest(client, workRequestId);
listWorkRequestErrors(client, workRequestId);
listWorkRequestLogs(client, workRequestId);
}
}
private static void getWorkRequest(WorkRequestClient client, String workRequestId) {
System.out.println("getWorkRequest");
GetWorkRequestRequest request =
GetWorkRequestRequest.builder().workRequestId(workRequestId).build();
GetWorkRequestResponse response = client.getWorkRequest(request);
System.out.println("getWorkRequests response: " + response.getWorkRequest());
}
private static void listWorkRequestErrors(WorkRequestClient client, String workRequestId) {
System.out.println("listWorkRequestErrors");
ListWorkRequestErrorsRequest request =
ListWorkRequestErrorsRequest.builder().workRequestId(workRequestId).build();
Iterable<ListWorkRequestErrorsResponse> responseIterator =
client.getPaginators().listWorkRequestErrorsResponseIterator(request);
for (ListWorkRequestErrorsResponse response : responseIterator) {
System.out.println("listWorkRequestErrors response: " + response.getItems());
}
}
private static void listWorkRequestLogs(WorkRequestClient client, String workRequestId) {
System.out.println("listWorkRequestLogs");
ListWorkRequestLogsRequest request =
ListWorkRequestLogsRequest.builder().workRequestId(workRequestId).build();
Iterable<ListWorkRequestLogsResponse> responseIterator =
client.getPaginators().listWorkRequestLogsResponseIterator(request);
for (ListWorkRequestLogsResponse response : responseIterator) {
System.out.println("listWorkRequestLogs response: " + response.getItems());
}
}
private static WorkRequestClient getWorkRequestClient() throws IOException {
// 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(CONFIG_LOCATION, profile);
final ConfigFileReader.ConfigFile configFile = ConfigFileReader.parseDefault();
final AuthenticationDetailsProvider provider =
new ConfigFileAuthenticationDetailsProvider(configFile);
WorkRequestClient client = new WorkRequestClient(provider);
return client;
}
}