Search in sources :

Example 1 with UndeployModelResponse

use of com.google.cloud.aiplatform.v1.UndeployModelResponse in project java-aiplatform by googleapis.

the class UndeployModelSample method undeployModelSample.

static void undeployModelSample(String project, String endpointId, String modelId) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    EndpointServiceSettings endpointServiceSettings = EndpointServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (EndpointServiceClient endpointServiceClient = EndpointServiceClient.create(endpointServiceSettings)) {
        String location = "us-central1";
        EndpointName endpointName = EndpointName.of(project, location, endpointId);
        ModelName modelName = ModelName.of(project, location, modelId);
        // key '0' assigns traffic for the newly deployed model
        // Traffic percentage values must add up to 100
        // Leave dictionary empty if endpoint should not accept any traffic
        Map<String, Integer> trafficSplit = new HashMap<>();
        trafficSplit.put("0", 100);
        OperationFuture<UndeployModelResponse, UndeployModelOperationMetadata> operation = endpointServiceClient.undeployModelAsync(endpointName.toString(), modelName.toString(), trafficSplit);
        System.out.format("Operation name: %s\n", operation.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        UndeployModelResponse undeployModelResponse = operation.get(180, TimeUnit.SECONDS);
        System.out.format("Undeploy Model Response: %s\n", undeployModelResponse);
    }
}
Also used : ModelName(com.google.cloud.aiplatform.v1.ModelName) EndpointName(com.google.cloud.aiplatform.v1.EndpointName) HashMap(java.util.HashMap) EndpointServiceClient(com.google.cloud.aiplatform.v1.EndpointServiceClient) UndeployModelResponse(com.google.cloud.aiplatform.v1.UndeployModelResponse) EndpointServiceSettings(com.google.cloud.aiplatform.v1.EndpointServiceSettings) UndeployModelOperationMetadata(com.google.cloud.aiplatform.v1.UndeployModelOperationMetadata)

Aggregations

EndpointName (com.google.cloud.aiplatform.v1.EndpointName)1 EndpointServiceClient (com.google.cloud.aiplatform.v1.EndpointServiceClient)1 EndpointServiceSettings (com.google.cloud.aiplatform.v1.EndpointServiceSettings)1 ModelName (com.google.cloud.aiplatform.v1.ModelName)1 UndeployModelOperationMetadata (com.google.cloud.aiplatform.v1.UndeployModelOperationMetadata)1 UndeployModelResponse (com.google.cloud.aiplatform.v1.UndeployModelResponse)1 HashMap (java.util.HashMap)1