com.oracle.bmc.optimizer.OptimizerWaiters Maven / Gradle / Ivy
Show all versions of oci-java-sdk-optimizer Show documentation
/**
* Copyright (c) 2016, 2024, 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.
*/
package com.oracle.bmc.optimizer;
import com.oracle.bmc.optimizer.requests.*;
import com.oracle.bmc.optimizer.responses.*;
/**
* Collection of helper methods to produce {@link com.oracle.bmc.waiter.Waiter}s for different
* resources of Optimizer.
*
* The default configuration used is defined by {@link
* com.oracle.bmc.waiter.Waiters.Waiters#DEFAULT_POLLING_WAITER}.
*/
@jakarta.annotation.Generated(value = "OracleSDKGenerator", comments = "API Version: 20200606")
public class OptimizerWaiters {
private final java.util.concurrent.ExecutorService executorService;
private final Optimizer client;
public OptimizerWaiters(
java.util.concurrent.ExecutorService executorService, Optimizer client) {
this.executorService = executorService;
this.client = client;
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the default configuration.
*
* @param request the request to send
* @param targetState the desired states to wait for. If multiple states are provided then the
* waiter will return once the resource reaches any of the provided states
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter forCategory(
GetCategoryRequest request,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forCategory(
com.oracle.bmc.waiter.Waiters.DEFAULT_POLLING_WAITER, request, targetStates);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param targetState the desired state to wait for
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter forCategory(
GetCategoryRequest request,
com.oracle.bmc.optimizer.model.LifecycleState targetState,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy) {
com.oracle.bmc.util.internal.Validate.notNull(
targetState, "The targetState cannot be null");
return forCategory(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetState);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @param targetStates the desired states to wait for. The waiter will return once the resource
* reaches any of the provided states
* @return a new {@code Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter forCategory(
GetCategoryRequest request,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forCategory(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetStates);
}
// Helper method to create a new Waiter for Category.
private com.oracle.bmc.waiter.Waiter forCategory(
com.oracle.bmc.waiter.BmcGenericWaiter waiter,
final GetCategoryRequest request,
final com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
final java.util.Set targetStatesSet =
new java.util.HashSet<>(java.util.Arrays.asList(targetStates));
return new com.oracle.bmc.waiter.internal.SimpleWaiterImpl<>(
executorService,
waiter.toCallable(
() -> request,
new java.util.function.Function() {
@Override
public GetCategoryResponse apply(GetCategoryRequest request) {
return client.getCategory(request);
}
},
new java.util.function.Predicate() {
@Override
public boolean test(GetCategoryResponse response) {
return targetStatesSet.contains(
response.getCategory().getLifecycleState());
}
},
targetStatesSet.contains(
com.oracle.bmc.optimizer.model.LifecycleState.Deleted)),
request);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the default configuration.
*
* @param request the request to send
* @param targetState the desired states to wait for. If multiple states are provided then the
* waiter will return once the resource reaches any of the provided states
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forEnrollmentStatus(
GetEnrollmentStatusRequest request,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forEnrollmentStatus(
com.oracle.bmc.waiter.Waiters.DEFAULT_POLLING_WAITER, request, targetStates);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param targetState the desired state to wait for
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forEnrollmentStatus(
GetEnrollmentStatusRequest request,
com.oracle.bmc.optimizer.model.LifecycleState targetState,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy) {
com.oracle.bmc.util.internal.Validate.notNull(
targetState, "The targetState cannot be null");
return forEnrollmentStatus(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetState);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @param targetStates the desired states to wait for. The waiter will return once the resource
* reaches any of the provided states
* @return a new {@code Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forEnrollmentStatus(
GetEnrollmentStatusRequest request,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forEnrollmentStatus(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetStates);
}
// Helper method to create a new Waiter for EnrollmentStatus.
private com.oracle.bmc.waiter.Waiter
forEnrollmentStatus(
com.oracle.bmc.waiter.BmcGenericWaiter waiter,
final GetEnrollmentStatusRequest request,
final com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
final java.util.Set targetStatesSet =
new java.util.HashSet<>(java.util.Arrays.asList(targetStates));
return new com.oracle.bmc.waiter.internal.SimpleWaiterImpl<>(
executorService,
waiter.toCallable(
() -> request,
new java.util.function.Function<
GetEnrollmentStatusRequest, GetEnrollmentStatusResponse>() {
@Override
public GetEnrollmentStatusResponse apply(
GetEnrollmentStatusRequest request) {
return client.getEnrollmentStatus(request);
}
},
new java.util.function.Predicate() {
@Override
public boolean test(GetEnrollmentStatusResponse response) {
return targetStatesSet.contains(
response.getEnrollmentStatus().getLifecycleState());
}
},
targetStatesSet.contains(
com.oracle.bmc.optimizer.model.LifecycleState.Deleted)),
request);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the default configuration.
*
* @param request the request to send
* @param targetState the desired states to wait for. If multiple states are provided then the
* waiter will return once the resource reaches any of the provided states
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter forProfile(
GetProfileRequest request,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forProfile(
com.oracle.bmc.waiter.Waiters.DEFAULT_POLLING_WAITER, request, targetStates);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param targetState the desired state to wait for
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter forProfile(
GetProfileRequest request,
com.oracle.bmc.optimizer.model.LifecycleState targetState,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy) {
com.oracle.bmc.util.internal.Validate.notNull(
targetState, "The targetState cannot be null");
return forProfile(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetState);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @param targetStates the desired states to wait for. The waiter will return once the resource
* reaches any of the provided states
* @return a new {@code Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter forProfile(
GetProfileRequest request,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forProfile(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetStates);
}
// Helper method to create a new Waiter for Profile.
private com.oracle.bmc.waiter.Waiter forProfile(
com.oracle.bmc.waiter.BmcGenericWaiter waiter,
final GetProfileRequest request,
final com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
final java.util.Set targetStatesSet =
new java.util.HashSet<>(java.util.Arrays.asList(targetStates));
return new com.oracle.bmc.waiter.internal.SimpleWaiterImpl<>(
executorService,
waiter.toCallable(
() -> request,
new java.util.function.Function() {
@Override
public GetProfileResponse apply(GetProfileRequest request) {
return client.getProfile(request);
}
},
new java.util.function.Predicate() {
@Override
public boolean test(GetProfileResponse response) {
return targetStatesSet.contains(
response.getProfile().getLifecycleState());
}
},
targetStatesSet.contains(
com.oracle.bmc.optimizer.model.LifecycleState.Deleted)),
request);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the default configuration.
*
* @param request the request to send
* @param targetState the desired states to wait for. If multiple states are provided then the
* waiter will return once the resource reaches any of the provided states
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forRecommendation(
GetRecommendationRequest request,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forRecommendation(
com.oracle.bmc.waiter.Waiters.DEFAULT_POLLING_WAITER, request, targetStates);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param targetState the desired state to wait for
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forRecommendation(
GetRecommendationRequest request,
com.oracle.bmc.optimizer.model.LifecycleState targetState,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy) {
com.oracle.bmc.util.internal.Validate.notNull(
targetState, "The targetState cannot be null");
return forRecommendation(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetState);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @param targetStates the desired states to wait for. The waiter will return once the resource
* reaches any of the provided states
* @return a new {@code Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forRecommendation(
GetRecommendationRequest request,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forRecommendation(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetStates);
}
// Helper method to create a new Waiter for Recommendation.
private com.oracle.bmc.waiter.Waiter
forRecommendation(
com.oracle.bmc.waiter.BmcGenericWaiter waiter,
final GetRecommendationRequest request,
final com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
final java.util.Set targetStatesSet =
new java.util.HashSet<>(java.util.Arrays.asList(targetStates));
return new com.oracle.bmc.waiter.internal.SimpleWaiterImpl<>(
executorService,
waiter.toCallable(
() -> request,
new java.util.function.Function<
GetRecommendationRequest, GetRecommendationResponse>() {
@Override
public GetRecommendationResponse apply(
GetRecommendationRequest request) {
return client.getRecommendation(request);
}
},
new java.util.function.Predicate() {
@Override
public boolean test(GetRecommendationResponse response) {
return targetStatesSet.contains(
response.getRecommendation().getLifecycleState());
}
},
targetStatesSet.contains(
com.oracle.bmc.optimizer.model.LifecycleState.Deleted)),
request);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the default configuration.
*
* @param request the request to send
* @param targetState the desired states to wait for. If multiple states are provided then the
* waiter will return once the resource reaches any of the provided states
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forResourceAction(
GetResourceActionRequest request,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forResourceAction(
com.oracle.bmc.waiter.Waiters.DEFAULT_POLLING_WAITER, request, targetStates);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param targetState the desired state to wait for
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forResourceAction(
GetResourceActionRequest request,
com.oracle.bmc.optimizer.model.LifecycleState targetState,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy) {
com.oracle.bmc.util.internal.Validate.notNull(
targetState, "The targetState cannot be null");
return forResourceAction(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetState);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@link com.oracle.bmc.waiter.DelayStrategy} to use
* @param targetStates the desired states to wait for. The waiter will return once the resource
* reaches any of the provided states
* @return a new {@code Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forResourceAction(
GetResourceActionRequest request,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy,
com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
com.oracle.bmc.util.internal.Validate.notEmpty(
targetStates, "At least one targetState must be provided");
com.oracle.bmc.util.internal.Validate.noNullElements(
targetStates, "Null targetState values are not permitted");
return forResourceAction(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request,
targetStates);
}
// Helper method to create a new Waiter for ResourceAction.
private com.oracle.bmc.waiter.Waiter
forResourceAction(
com.oracle.bmc.waiter.BmcGenericWaiter waiter,
final GetResourceActionRequest request,
final com.oracle.bmc.optimizer.model.LifecycleState... targetStates) {
final java.util.Set targetStatesSet =
new java.util.HashSet<>(java.util.Arrays.asList(targetStates));
return new com.oracle.bmc.waiter.internal.SimpleWaiterImpl<>(
executorService,
waiter.toCallable(
() -> request,
new java.util.function.Function<
GetResourceActionRequest, GetResourceActionResponse>() {
@Override
public GetResourceActionResponse apply(
GetResourceActionRequest request) {
return client.getResourceAction(request);
}
},
new java.util.function.Predicate() {
@Override
public boolean test(GetResourceActionResponse response) {
return targetStatesSet.contains(
response.getResourceAction().getLifecycleState());
}
},
targetStatesSet.contains(
com.oracle.bmc.optimizer.model.LifecycleState.Deleted)),
request);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using default configuration.
*
* @param request the request to send
* @return a new {@code Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forWorkRequest(GetWorkRequestRequest request) {
return forWorkRequest(com.oracle.bmc.waiter.Waiters.DEFAULT_POLLING_WAITER, request);
}
/**
* Creates a new {@link com.oracle.bmc.waiter.Waiter} using the provided configuration.
*
* @param request the request to send
* @param terminationStrategy the {@link com.oracle.bmc.waiter.TerminationStrategy} to use
* @param delayStrategy the {@linkcom.oracle.bmc.waiter. DelayStrategy} to use
* @return a new {@code com.oracle.bmc.waiter.Waiter} instance
*/
public com.oracle.bmc.waiter.Waiter
forWorkRequest(
GetWorkRequestRequest request,
com.oracle.bmc.waiter.TerminationStrategy terminationStrategy,
com.oracle.bmc.waiter.DelayStrategy delayStrategy) {
return forWorkRequest(
com.oracle.bmc.waiter.Waiters.newWaiter(terminationStrategy, delayStrategy),
request);
}
// Helper method to create a new Waiter for WorkRequest.
private com.oracle.bmc.waiter.Waiter
forWorkRequest(
com.oracle.bmc.waiter.BmcGenericWaiter waiter,
final GetWorkRequestRequest request) {
return new com.oracle.bmc.waiter.internal.SimpleWaiterImpl<>(
executorService,
waiter.toCallable(
() -> request,
new java.util.function.Function<
GetWorkRequestRequest, GetWorkRequestResponse>() {
@Override
public GetWorkRequestResponse apply(GetWorkRequestRequest request) {
return client.getWorkRequest(request);
}
},
new java.util.function.Predicate() {
@Override
public boolean test(GetWorkRequestResponse response) {
// work requests are complete once the time finished is available
return response.getWorkRequest().getTimeFinished() != null;
}
},
false),
request);
}
}