iartiukhov commented on code in PR #7122: URL: https://github.com/apache/ignite-3/pull/7122#discussion_r2647831294
########## examples/java/src/main/java/org/apache/ignite/example/util/DeployComputeUnit.java: ########## @@ -0,0 +1,250 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.util; + +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.awaitility.Awaitility.await; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +/** + * Utility class for deploying Ignite compute units. + * <p> + * Note: The deployment unit JAR is now built at compile time via the deploymentUnitJar Gradle task, + * not at runtime. This eliminates the need for runtime JAR building. + * </p> + */ +public class DeployComputeUnit { + + private static final String BASE_URL = "http://localhost:10300"; + private static final HttpClient HTTP = HttpClient.newHttpClient(); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final int DEPLOYMENT_TIMEOUT_SECONDS = 30; + + + /** + * Checks if a deployment unit already exists on the cluster with DEPLOYED status. + * + * @param unitId Deployment unit ID. + * @param version Deployment version. + * @return True if deployment exists with DEPLOYED status. + * @throws Exception If request fails. + */ + private static boolean isDeployed(String unitId, String version) throws Exception { + HttpRequest req = HttpRequest.newBuilder() + .uri(new URI(BASE_URL + "/management/v1/deployment/cluster/units/" + unitId)) + .GET() + .build(); + + HttpResponse<String> resp = HTTP.send(req, HttpResponse.BodyHandlers.ofString()); + + if (resp.statusCode() != 200) { + return false; + } + + // Parse JSON response to check status + JsonNode root = OBJECT_MAPPER.readTree(resp.body()); + JsonNode versionToStatus = root.path("versionToStatus"); + + if (versionToStatus.isArray()) { Review Comment: Looks the clause is always `false` because of the error in JSON parsing logic. So the [deployment check](https://github.com/apache/ignite-3/pull/7122/files#diff-5dbd940687ef85bfa02b01b5b57b7392116aad8e26b27c5ae0700ba8a3249de6R148) does not succeed and fails with timeout. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
