@Generated(value="by gapic-generator") public class AlertPolicyServiceClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
AlertPolicy response = alertPolicyServiceClient.getAlertPolicy(name);
}
Note: close() needs to be called on the alertPolicyServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of AlertPolicyServiceSettings to create(). For example:
To customize credentials:
AlertPolicyServiceSettings alertPolicyServiceSettings =
AlertPolicyServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
AlertPolicyServiceClient alertPolicyServiceClient =
AlertPolicyServiceClient.create(alertPolicyServiceSettings);
To customize the endpoint:
AlertPolicyServiceSettings alertPolicyServiceSettings =
AlertPolicyServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
AlertPolicyServiceClient alertPolicyServiceClient =
AlertPolicyServiceClient.create(alertPolicyServiceSettings);
Modifier and Type | Class and Description |
---|---|
static class |
AlertPolicyServiceClient.ListAlertPoliciesFixedSizeCollection |
static class |
AlertPolicyServiceClient.ListAlertPoliciesPage |
static class |
AlertPolicyServiceClient.ListAlertPoliciesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
AlertPolicyServiceClient(AlertPolicyServiceSettings settings)
Constructs an instance of AlertPolicyServiceClient, using the given settings.
|
protected |
AlertPolicyServiceClient(AlertPolicyServiceStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static AlertPolicyServiceClient |
create()
Constructs an instance of AlertPolicyServiceClient with default settings.
|
static AlertPolicyServiceClient |
create(AlertPolicyServiceSettings settings)
Constructs an instance of AlertPolicyServiceClient, using the given settings.
|
static AlertPolicyServiceClient |
create(AlertPolicyServiceStub stub)
Constructs an instance of AlertPolicyServiceClient, using the given stub for making calls.
|
com.google.monitoring.v3.AlertPolicy |
createAlertPolicy(com.google.monitoring.v3.CreateAlertPolicyRequest request)
Creates a new alerting policy.
|
com.google.monitoring.v3.AlertPolicy |
createAlertPolicy(com.google.monitoring.v3.ProjectName name,
com.google.monitoring.v3.AlertPolicy alertPolicy)
Creates a new alerting policy.
|
com.google.monitoring.v3.AlertPolicy |
createAlertPolicy(String name,
com.google.monitoring.v3.AlertPolicy alertPolicy)
Creates a new alerting policy.
|
UnaryCallable<com.google.monitoring.v3.CreateAlertPolicyRequest,com.google.monitoring.v3.AlertPolicy> |
createAlertPolicyCallable()
Creates a new alerting policy.
|
void |
deleteAlertPolicy(com.google.monitoring.v3.AlertPolicyName name)
Deletes an alerting policy.
|
void |
deleteAlertPolicy(com.google.monitoring.v3.DeleteAlertPolicyRequest request)
Deletes an alerting policy.
|
void |
deleteAlertPolicy(String name)
Deletes an alerting policy.
|
UnaryCallable<com.google.monitoring.v3.DeleteAlertPolicyRequest,Empty> |
deleteAlertPolicyCallable()
Deletes an alerting policy.
|
com.google.monitoring.v3.AlertPolicy |
getAlertPolicy(com.google.monitoring.v3.AlertPolicyName name)
Gets a single alerting policy.
|
com.google.monitoring.v3.AlertPolicy |
getAlertPolicy(com.google.monitoring.v3.GetAlertPolicyRequest request)
Gets a single alerting policy.
|
com.google.monitoring.v3.AlertPolicy |
getAlertPolicy(String name)
Gets a single alerting policy.
|
UnaryCallable<com.google.monitoring.v3.GetAlertPolicyRequest,com.google.monitoring.v3.AlertPolicy> |
getAlertPolicyCallable()
Gets a single alerting policy.
|
AlertPolicyServiceSettings |
getSettings() |
AlertPolicyServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
AlertPolicyServiceClient.ListAlertPoliciesPagedResponse |
listAlertPolicies(com.google.monitoring.v3.ListAlertPoliciesRequest request)
Lists the existing alerting policies for the project.
|
AlertPolicyServiceClient.ListAlertPoliciesPagedResponse |
listAlertPolicies(com.google.monitoring.v3.ProjectName name)
Lists the existing alerting policies for the project.
|
AlertPolicyServiceClient.ListAlertPoliciesPagedResponse |
listAlertPolicies(String name)
Lists the existing alerting policies for the project.
|
UnaryCallable<com.google.monitoring.v3.ListAlertPoliciesRequest,com.google.monitoring.v3.ListAlertPoliciesResponse> |
listAlertPoliciesCallable()
Lists the existing alerting policies for the project.
|
UnaryCallable<com.google.monitoring.v3.ListAlertPoliciesRequest,AlertPolicyServiceClient.ListAlertPoliciesPagedResponse> |
listAlertPoliciesPagedCallable()
Lists the existing alerting policies for the project.
|
void |
shutdown() |
void |
shutdownNow() |
com.google.monitoring.v3.AlertPolicy |
updateAlertPolicy(FieldMask updateMask,
com.google.monitoring.v3.AlertPolicy alertPolicy)
Updates an alerting policy.
|
com.google.monitoring.v3.AlertPolicy |
updateAlertPolicy(com.google.monitoring.v3.UpdateAlertPolicyRequest request)
Updates an alerting policy.
|
UnaryCallable<com.google.monitoring.v3.UpdateAlertPolicyRequest,com.google.monitoring.v3.AlertPolicy> |
updateAlertPolicyCallable()
Updates an alerting policy.
|
protected AlertPolicyServiceClient(AlertPolicyServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected AlertPolicyServiceClient(AlertPolicyServiceStub stub)
public static final AlertPolicyServiceClient create() throws IOException
IOException
public static final AlertPolicyServiceClient create(AlertPolicyServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final AlertPolicyServiceClient create(AlertPolicyServiceStub stub)
public final AlertPolicyServiceSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public AlertPolicyServiceStub getStub()
public final AlertPolicyServiceClient.ListAlertPoliciesPagedResponse listAlertPolicies(com.google.monitoring.v3.ProjectName name)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
for (AlertPolicy element : alertPolicyServiceClient.listAlertPolicies(name).iterateAll()) {
// doThingsWith(element);
}
}
name
- The project whose alert policies are to be listed. The format is
projects/[PROJECT_ID]
Note that this field names the parent container in which the alerting policies to be listed are stored. To retrieve a single alerting policy by name, use the [GetAlertPolicy][google.monitoring.v3.AlertPolicyService.GetAlertPolicy] operation, instead.
ApiException
- if the remote call failspublic final AlertPolicyServiceClient.ListAlertPoliciesPagedResponse listAlertPolicies(String name)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
for (AlertPolicy element : alertPolicyServiceClient.listAlertPolicies(name.toString()).iterateAll()) {
// doThingsWith(element);
}
}
name
- The project whose alert policies are to be listed. The format is
projects/[PROJECT_ID]
Note that this field names the parent container in which the alerting policies to be listed are stored. To retrieve a single alerting policy by name, use the [GetAlertPolicy][google.monitoring.v3.AlertPolicyService.GetAlertPolicy] operation, instead.
ApiException
- if the remote call failspublic final AlertPolicyServiceClient.ListAlertPoliciesPagedResponse listAlertPolicies(com.google.monitoring.v3.ListAlertPoliciesRequest request)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListAlertPoliciesRequest request = ListAlertPoliciesRequest.newBuilder()
.setName(name.toString())
.build();
for (AlertPolicy element : alertPolicyServiceClient.listAlertPolicies(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.ListAlertPoliciesRequest,AlertPolicyServiceClient.ListAlertPoliciesPagedResponse> listAlertPoliciesPagedCallable()
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListAlertPoliciesRequest request = ListAlertPoliciesRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<ListAlertPoliciesPagedResponse> future = alertPolicyServiceClient.listAlertPoliciesPagedCallable().futureCall(request);
// Do something
for (AlertPolicy element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.monitoring.v3.ListAlertPoliciesRequest,com.google.monitoring.v3.ListAlertPoliciesResponse> listAlertPoliciesCallable()
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ListAlertPoliciesRequest request = ListAlertPoliciesRequest.newBuilder()
.setName(name.toString())
.build();
while (true) {
ListAlertPoliciesResponse response = alertPolicyServiceClient.listAlertPoliciesCallable().call(request);
for (AlertPolicy element : response.getAlertPoliciesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final com.google.monitoring.v3.AlertPolicy getAlertPolicy(com.google.monitoring.v3.AlertPolicyName name)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
AlertPolicy response = alertPolicyServiceClient.getAlertPolicy(name);
}
name
- The alerting policy to retrieve. The format is
projects/[PROJECT_ID]/alertPolicies/[ALERT_POLICY_ID]
ApiException
- if the remote call failspublic final com.google.monitoring.v3.AlertPolicy getAlertPolicy(String name)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
AlertPolicy response = alertPolicyServiceClient.getAlertPolicy(name.toString());
}
name
- The alerting policy to retrieve. The format is
projects/[PROJECT_ID]/alertPolicies/[ALERT_POLICY_ID]
ApiException
- if the remote call failspublic final com.google.monitoring.v3.AlertPolicy getAlertPolicy(com.google.monitoring.v3.GetAlertPolicyRequest request)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
GetAlertPolicyRequest request = GetAlertPolicyRequest.newBuilder()
.setName(name.toString())
.build();
AlertPolicy response = alertPolicyServiceClient.getAlertPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.GetAlertPolicyRequest,com.google.monitoring.v3.AlertPolicy> getAlertPolicyCallable()
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
GetAlertPolicyRequest request = GetAlertPolicyRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<AlertPolicy> future = alertPolicyServiceClient.getAlertPolicyCallable().futureCall(request);
// Do something
AlertPolicy response = future.get();
}
public final com.google.monitoring.v3.AlertPolicy createAlertPolicy(com.google.monitoring.v3.ProjectName name, com.google.monitoring.v3.AlertPolicy alertPolicy)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
AlertPolicy response = alertPolicyServiceClient.createAlertPolicy(name, alertPolicy);
}
name
- The project in which to create the alerting policy. The format is
`projects/[PROJECT_ID]`.
Note that this field names the parent container in which the alerting policy will be written, not the name of the created policy. The alerting policy that is returned will have a name that contains a normalized representation of this name as a prefix but adds a suffix of the form `/alertPolicies/[POLICY_ID]`, identifying the policy in the container.
alertPolicy
- The requested alerting policy. You should omit the `name` field in this
policy. The name will be returned in the new policy, including a new [ALERT_POLICY_ID]
value.ApiException
- if the remote call failspublic final com.google.monitoring.v3.AlertPolicy createAlertPolicy(String name, com.google.monitoring.v3.AlertPolicy alertPolicy)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
AlertPolicy response = alertPolicyServiceClient.createAlertPolicy(name.toString(), alertPolicy);
}
name
- The project in which to create the alerting policy. The format is
`projects/[PROJECT_ID]`.
Note that this field names the parent container in which the alerting policy will be written, not the name of the created policy. The alerting policy that is returned will have a name that contains a normalized representation of this name as a prefix but adds a suffix of the form `/alertPolicies/[POLICY_ID]`, identifying the policy in the container.
alertPolicy
- The requested alerting policy. You should omit the `name` field in this
policy. The name will be returned in the new policy, including a new [ALERT_POLICY_ID]
value.ApiException
- if the remote call failspublic final com.google.monitoring.v3.AlertPolicy createAlertPolicy(com.google.monitoring.v3.CreateAlertPolicyRequest request)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
CreateAlertPolicyRequest request = CreateAlertPolicyRequest.newBuilder()
.setName(name.toString())
.setAlertPolicy(alertPolicy)
.build();
AlertPolicy response = alertPolicyServiceClient.createAlertPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.CreateAlertPolicyRequest,com.google.monitoring.v3.AlertPolicy> createAlertPolicyCallable()
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
CreateAlertPolicyRequest request = CreateAlertPolicyRequest.newBuilder()
.setName(name.toString())
.setAlertPolicy(alertPolicy)
.build();
ApiFuture<AlertPolicy> future = alertPolicyServiceClient.createAlertPolicyCallable().futureCall(request);
// Do something
AlertPolicy response = future.get();
}
public final void deleteAlertPolicy(com.google.monitoring.v3.AlertPolicyName name)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
alertPolicyServiceClient.deleteAlertPolicy(name);
}
name
- The alerting policy to delete. The format is:
projects/[PROJECT_ID]/alertPolicies/[ALERT_POLICY_ID]
For more information, see [AlertPolicy][google.monitoring.v3.AlertPolicy].
ApiException
- if the remote call failspublic final void deleteAlertPolicy(String name)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
alertPolicyServiceClient.deleteAlertPolicy(name.toString());
}
name
- The alerting policy to delete. The format is:
projects/[PROJECT_ID]/alertPolicies/[ALERT_POLICY_ID]
For more information, see [AlertPolicy][google.monitoring.v3.AlertPolicy].
ApiException
- if the remote call failspublic final void deleteAlertPolicy(com.google.monitoring.v3.DeleteAlertPolicyRequest request)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
DeleteAlertPolicyRequest request = DeleteAlertPolicyRequest.newBuilder()
.setName(name.toString())
.build();
alertPolicyServiceClient.deleteAlertPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.DeleteAlertPolicyRequest,Empty> deleteAlertPolicyCallable()
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicyName name = AlertPolicyName.of("[PROJECT]", "[ALERT_POLICY]");
DeleteAlertPolicyRequest request = DeleteAlertPolicyRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Void> future = alertPolicyServiceClient.deleteAlertPolicyCallable().futureCall(request);
// Do something
future.get();
}
public final com.google.monitoring.v3.AlertPolicy updateAlertPolicy(FieldMask updateMask, com.google.monitoring.v3.AlertPolicy alertPolicy)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
FieldMask updateMask = FieldMask.newBuilder().build();
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
AlertPolicy response = alertPolicyServiceClient.updateAlertPolicy(updateMask, alertPolicy);
}
updateMask
- Optional. A list of alerting policy field names. If this field is not empty,
each listed field in the existing alerting policy is set to the value of the corresponding
field in the supplied policy (`alert_policy`), or to the field's default value if the field
is not in the supplied alerting policy. Fields not listed retain their previous value.
Examples of valid field masks include `display_name`, `documentation`, `documentation.content`, `documentation.mime_type`, `user_labels`, `user_label.nameofkey`, `enabled`, `conditions`, `combiner`, etc.
If this field is empty, then the supplied alerting policy replaces the existing policy. It is the same as deleting the existing policy and adding the supplied policy, except for the following:
+ The new policy will have the same `[ALERT_POLICY_ID]` as the former policy. This gives you continuity with the former policy in your notifications and incidents. + Conditions in the new policy will keep their former `[CONDITION_ID]` if the supplied condition includes the `name` field with that `[CONDITION_ID]`. If the supplied condition omits the `name` field, then a new `[CONDITION_ID]` is created.
alertPolicy
- Required. The updated alerting policy or the updated values for the fields
listed in `update_mask`. If `update_mask` is not empty, any fields in this policy that are
not in `update_mask` are ignored.ApiException
- if the remote call failspublic final com.google.monitoring.v3.AlertPolicy updateAlertPolicy(com.google.monitoring.v3.UpdateAlertPolicyRequest request)
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
UpdateAlertPolicyRequest request = UpdateAlertPolicyRequest.newBuilder()
.setAlertPolicy(alertPolicy)
.build();
AlertPolicy response = alertPolicyServiceClient.updateAlertPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.monitoring.v3.UpdateAlertPolicyRequest,com.google.monitoring.v3.AlertPolicy> updateAlertPolicyCallable()
Sample code:
try (AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.create()) {
AlertPolicy alertPolicy = AlertPolicy.newBuilder().build();
UpdateAlertPolicyRequest request = UpdateAlertPolicyRequest.newBuilder()
.setAlertPolicy(alertPolicy)
.build();
ApiFuture<AlertPolicy> future = alertPolicyServiceClient.updateAlertPolicyCallable().futureCall(request);
// Do something
AlertPolicy response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.