PakhomovAlexander commented on code in PR #1733:
URL: https://github.com/apache/ignite-3/pull/1733#discussion_r1121770750
##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/ConfigurationManager.java:
##########
@@ -91,6 +91,7 @@ public void stop() throws Exception {
public void bootstrap(Path configPath) throws InterruptedException,
ExecutionException {
ConfigObject hoconCfg =
ConfigFactory.parseFile(configPath.toFile()).root();
+
Review Comment:
empty line
##########
modules/rest-api/src/main/java/org/apache/ignite/internal/rest/constants/HttpCode.java:
##########
@@ -24,6 +24,10 @@ public enum HttpCode {
OK(200, "OK"),
BAD_REQUEST(400, "Bad Request"),
NOT_FOUND(404, "Not Found"),
+ /**
+ * May be used in case of "Already exists" problem.
Review Comment:
could you use one-line comment here?
##########
modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/deployment/UnitStatusDto.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.internal.rest.api.deployment;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonGetter;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.deployment.UnitStatus;
+import org.apache.ignite.deployment.version.Version;
+
+/**
+ * DTO of {@link UnitStatus}.
+ */
+@Schema(name = "UnitStatus", description = "Unit status.")
+public class UnitStatusDto {
+
+ /**
+ * Unit identifier.
+ */
+ private final String id;
+
+ /**
+ * Map from existing unit version to list of nodes consistent ids where
unit deployed.
+ */
+ private final Map<String, List<String>> versionToConsistentIds;
+
+ @JsonCreator
+ public UnitStatusDto(@JsonProperty("id") String id,
+ @JsonProperty("versionToNodes") Map<String, List<String>>
versionToConsistentIds) {
+ this.id = id;
+ this.versionToConsistentIds = versionToConsistentIds;
+ }
+
+ /**
+ * Returns the metric source name.
+ *
+ * @return metric source name
Review Comment:
I think this code does not relate to metrics.
##########
modules/rest/openapi/openapi.yaml:
##########
@@ -316,6 +319,166 @@ paths:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
+ /management/v1/deployment/deploy:
Review Comment:
/deployment/deploy looks really weird...
##########
modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/deployment/DeploymentManagementControllerTest.java:
##########
@@ -0,0 +1,247 @@
+/*
+ * 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.internal.rest.deployment;
+
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.WRITE;
+import static org.apache.ignite.internal.rest.constants.HttpCode.BAD_REQUEST;
+import static org.apache.ignite.internal.rest.constants.HttpCode.CONFLICT;
+import static org.apache.ignite.internal.rest.constants.HttpCode.NOT_FOUND;
+import static org.apache.ignite.internal.rest.constants.HttpCode.OK;
+import static
org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.is;
+
+import io.micronaut.http.HttpRequest;
+import io.micronaut.http.HttpResponse;
+import io.micronaut.http.MediaType;
+import io.micronaut.http.MutableHttpRequest;
+import io.micronaut.http.client.HttpClient;
+import io.micronaut.http.client.annotation.Client;
+import io.micronaut.http.client.exceptions.HttpClientResponseException;
+import io.micronaut.http.client.multipart.MultipartBody;
+import jakarta.inject.Inject;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SeekableByteChannel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.deployment.version.Version;
+import org.apache.ignite.internal.rest.api.deployment.UnitStatusDto;
+import org.apache.ignite.internal.testframework.IntegrationTestBase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+/**
+ * Integration test for REST controller {@link DeploymentManagementController}.
+ */
+public class DeploymentManagementControllerTest extends IntegrationTestBase {
+ private static Path dummyFile;
+
+ private static final long SIZE_IN_BYTES = 1024L;
+ @Inject
Review Comment:
add empty line please
##########
modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/deployment/DeploymentManagementControllerTest.java:
##########
@@ -0,0 +1,247 @@
+/*
+ * 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.internal.rest.deployment;
+
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.WRITE;
+import static org.apache.ignite.internal.rest.constants.HttpCode.BAD_REQUEST;
+import static org.apache.ignite.internal.rest.constants.HttpCode.CONFLICT;
+import static org.apache.ignite.internal.rest.constants.HttpCode.NOT_FOUND;
+import static org.apache.ignite.internal.rest.constants.HttpCode.OK;
+import static
org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.is;
+
+import io.micronaut.http.HttpRequest;
+import io.micronaut.http.HttpResponse;
+import io.micronaut.http.MediaType;
+import io.micronaut.http.MutableHttpRequest;
+import io.micronaut.http.client.HttpClient;
+import io.micronaut.http.client.annotation.Client;
+import io.micronaut.http.client.exceptions.HttpClientResponseException;
+import io.micronaut.http.client.multipart.MultipartBody;
+import jakarta.inject.Inject;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SeekableByteChannel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.deployment.version.Version;
+import org.apache.ignite.internal.rest.api.deployment.UnitStatusDto;
+import org.apache.ignite.internal.testframework.IntegrationTestBase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+/**
+ * Integration test for REST controller {@link DeploymentManagementController}.
+ */
+public class DeploymentManagementControllerTest extends IntegrationTestBase {
+ private static Path dummyFile;
+
+ private static final long SIZE_IN_BYTES = 1024L;
+ @Inject
+ @Client(NODE_URL + "/management/v1/deployment")
+ HttpClient client;
+
+ @BeforeEach
+ public void setup(TestInfo testInfo) throws IOException {
+ startNodes(testInfo);
+ String metaStorageNodeName = testNodeName(testInfo, 0);
+ initializeCluster(metaStorageNodeName);
+
+ dummyFile = WORK_DIR.resolve("dummy.txt");
+
+ if (!Files.exists(dummyFile)) {
+ try (SeekableByteChannel channel = Files.newByteChannel(dummyFile,
WRITE, CREATE)) {
+ channel.position(SIZE_IN_BYTES - 4);
+
+ ByteBuffer buf = ByteBuffer.allocate(4).putInt(2);
+ buf.rewind();
+ channel.write(buf);
+ }
+ }
+ }
+
+ @AfterEach
+ public void cleanup(TestInfo testInfo) throws Exception {
+ stopNodes(testInfo);
+ }
+
+ @Test
+ public void testDeploySuccessful() {
+ String id = "testId";
+ String version = "1.1.1";
+ MultipartBody multipartBody = MultipartBody.builder()
+ .addPart("unitId", id)
+ .addPart("unitVersion", version)
+ .addPart("unitContent", dummyFile.toFile())
+ .build();
+ MutableHttpRequest<MultipartBody> post = HttpRequest.POST("deploy",
multipartBody)
+ .contentType(MediaType.MULTIPART_FORM_DATA);
+ HttpResponse<Object> response = client.toBlocking().exchange(post);
+
+ assertThat(response.code(), is(OK.code()));
+
+ MutableHttpRequest<Object> get = HttpRequest.GET("units");
+ UnitStatusDto status = client.toBlocking().retrieve(get,
UnitStatusDto.class);
+
+ assertThat(status.id(), is(id));
+ assertThat(status.versionToConsistentIds().keySet(),
equalTo(Set.of(version)));
+ assertThat(status.versionToConsistentIds().get(version),
hasItem(CLUSTER_NODE_NAMES.get(0)));
+ }
+
+ @Test
+ public void testDeployFailedWithoutId() {
+ MultipartBody multipartBody = MultipartBody.builder()
+ .addPart("unitVersion", "1.1.1")
+ .addPart("unitContent", dummyFile.toFile())
+ .build();
+ MutableHttpRequest<MultipartBody> post = HttpRequest.POST("deploy",
multipartBody)
+ .contentType(MediaType.MULTIPART_FORM_DATA);
+ try {
+ client.toBlocking().exchange(post);
Review Comment:
I would like to ask you to use `assertThrows` instead of try-catch
##########
modules/rest/openapi/openapi.yaml:
##########
@@ -316,6 +319,166 @@ paths:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
+ /management/v1/deployment/deploy:
+ post:
+ tags:
+ - deployment
+ description: Deploy provided unit to node.
+ operationId: deployUnit
+ parameters: []
+ requestBody:
+ content:
+ multipart/form-data:
+ schema:
+ required:
+ - unitContent
+ - unitId
+ type: object
+ properties:
+ unitId:
+ required:
+ - "true"
+ type: string
+ unitVersion:
+ type: string
+ unitContent:
+ required:
+ - "true"
+ type: string
+ format: binary
+ required: true
+ responses:
+ "200":
+ description: Unit deployed successfully.
+ content:
+ application/problem+json:
+ schema:
+ type: boolean
+ "500":
+ description: Internal error.
+ content:
+ application/problem+json:
+ schema:
+ $ref: '#/components/schemas/Problem'
+ /management/v1/deployment/status/{unitId}:
+ get:
+ tags:
+ - deployment
+ description: Status of unit with provided identifier.
+ operationId: status
+ parameters:
+ - name: unitId
+ in: path
+ required: true
+ schema:
+ required:
+ - "true"
+ type: string
+ responses:
+ "200":
+ description: Status returned successful.
+ content:
+ application/problem+json:
+ schema:
+ $ref: '#/components/schemas/UnitStatus'
+ "404":
+ description: Unit with provided identifier doesn't exist.
+ "500":
+ description: Internal error.
+ content:
+ application/problem+json:
+ schema:
+ $ref: '#/components/schemas/Problem'
+ /management/v1/deployment/undeploy:
+ post:
+ tags:
+ - deployment
+ description: Undeploy unit with provided unitId and unitVersion.
+ operationId: undeployUnit
+ parameters: []
+ requestBody:
+ content:
+ application/json:
+ schema:
+ required:
+ - unitId
+ type: object
+ properties:
+ unitId:
+ required:
+ - "true"
+ type: string
+ unitVersion:
+ type: string
+ required: true
+ responses:
+ "200":
+ description: Unit undeployed successfully.
+ content:
+ application/problem+json:
+ schema:
+ $ref: '#/components/schemas/Void'
+ "404":
+ description: Unit with provided identifier and version doesn't exist.
+ "500":
+ description: Internal error.
+ content:
+ application/problem+json:
+ schema:
+ $ref: '#/components/schemas/Problem'
+ /management/v1/deployment/units:
+ get:
+ tags:
+ - deployment
+ description: All units statutes.
+ operationId: units
+ parameters: []
+ responses:
+ "200":
+ description: All statutes returned successful.
+ content:
+ application/problem+json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/UnitStatus'
+ "500":
+ description: Internal error.
+ content:
+ application/problem+json:
+ schema:
+ $ref: '#/components/schemas/Problem'
+ /management/v1/deployment/versions/{unitId}:
+ get:
+ tags:
+ - deployment
+ description: All versions of unit with provided unit identifier.
+ operationId: versions
+ parameters:
+ - name: unitId
+ in: path
+ required: true
+ schema:
+ required:
+ - "true"
+ type: string
+ responses:
+ "200":
+ description: Versions returned successful.
+ content:
+ application/problem+json:
Review Comment:
Why we return problem+json in 200?
--
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]