|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.flink.fs.s3.common; |
| 20 | + |
| 21 | +import org.apache.flink.api.common.time.Deadline; |
| 22 | +import org.apache.flink.configuration.Configuration; |
| 23 | +import org.apache.flink.core.testutils.AllCallbackWrapper; |
| 24 | +import org.apache.flink.core.testutils.TestContainerExtension; |
| 25 | +import org.apache.flink.runtime.clusterframework.ApplicationStatus; |
| 26 | +import org.apache.flink.runtime.highavailability.AbstractHAJobRunITCase; |
| 27 | +import org.apache.flink.runtime.highavailability.FileSystemJobResultStore; |
| 28 | +import org.apache.flink.runtime.highavailability.JobResultStoreOptions; |
| 29 | +import org.apache.flink.runtime.testutils.CommonTestUtils; |
| 30 | + |
| 31 | +import org.apache.flink.shaded.guava30.com.google.common.collect.Iterables; |
| 32 | + |
| 33 | +import com.amazonaws.services.s3.model.S3ObjectSummary; |
| 34 | +import org.apache.commons.lang3.StringUtils; |
| 35 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 36 | + |
| 37 | +import java.time.Duration; |
| 38 | +import java.util.List; |
| 39 | + |
| 40 | +import static org.apache.flink.shaded.guava30.com.google.common.base.Predicates.not; |
| 41 | +import static org.assertj.core.api.Assertions.assertThat; |
| 42 | + |
| 43 | +/** |
| 44 | + * {@code HAJobRunOnMinioS3StoreITCase} covers a job run where the HA data is stored in Minio. The |
| 45 | + * implementation verifies whether the {@code JobResult} was written into the FileSystem-backed |
| 46 | + * {@code JobResultStore}. |
| 47 | + */ |
| 48 | +public abstract class HAJobRunOnMinioS3StoreITCase extends AbstractHAJobRunITCase { |
| 49 | + |
| 50 | + private static final String CLUSTER_ID = "test-cluster"; |
| 51 | + private static final String JOB_RESULT_STORE_FOLDER = "jrs"; |
| 52 | + |
| 53 | + @RegisterExtension |
| 54 | + private static final AllCallbackWrapper<TestContainerExtension<MinioTestContainer>> |
| 55 | + MINIO_EXTENSION = |
| 56 | + new AllCallbackWrapper<>(new TestContainerExtension<>(MinioTestContainer::new)); |
| 57 | + |
| 58 | + private static MinioTestContainer getMinioContainer() { |
| 59 | + return MINIO_EXTENSION.getCustomExtension().getTestContainer(); |
| 60 | + } |
| 61 | + |
| 62 | + private static String createS3URIWithSubPath(String... subfolders) { |
| 63 | + return getMinioContainer().getS3UriForDefaultBucket() + createSubPath(subfolders); |
| 64 | + } |
| 65 | + |
| 66 | + private static List<S3ObjectSummary> getObjectsFromJobResultStore() { |
| 67 | + return getMinioContainer() |
| 68 | + .getClient() |
| 69 | + .listObjects( |
| 70 | + getMinioContainer().getDefaultBucketName(), |
| 71 | + createSubPath(CLUSTER_ID, JOB_RESULT_STORE_FOLDER)) |
| 72 | + .getObjectSummaries(); |
| 73 | + } |
| 74 | + |
| 75 | + private static String createSubPath(String... subfolders) { |
| 76 | + final String pathSeparator = "/"; |
| 77 | + return pathSeparator + StringUtils.join(subfolders, pathSeparator); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + protected String getHAStoragePath() { |
| 82 | + return createS3URIWithSubPath(CLUSTER_ID); |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + protected Configuration createConfiguration() { |
| 87 | + final Configuration config = new Configuration(); |
| 88 | + |
| 89 | + getMinioContainer().setS3ConfigOptions(config); |
| 90 | + |
| 91 | + // JobResultStore configuration |
| 92 | + config.set(JobResultStoreOptions.DELETE_ON_COMMIT, Boolean.FALSE); |
| 93 | + config.set( |
| 94 | + JobResultStoreOptions.STORAGE_PATH, |
| 95 | + createS3URIWithSubPath(CLUSTER_ID, JOB_RESULT_STORE_FOLDER)); |
| 96 | + |
| 97 | + return config; |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + protected void runAfterJobTermination() throws Exception { |
| 102 | + CommonTestUtils.waitUntilCondition( |
| 103 | + () -> { |
| 104 | + final List<S3ObjectSummary> objects = getObjectsFromJobResultStore(); |
| 105 | + return objects.stream() |
| 106 | + .map(S3ObjectSummary::getKey) |
| 107 | + .anyMatch( |
| 108 | + FileSystemJobResultStore |
| 109 | + ::hasValidJobResultStoreEntryExtension) |
| 110 | + && objects.stream() |
| 111 | + .map(S3ObjectSummary::getKey) |
| 112 | + .noneMatch( |
| 113 | + FileSystemJobResultStore |
| 114 | + ::hasValidDirtyJobResultStoreEntryExtension); |
| 115 | + }, |
| 116 | + Deadline.fromNow(Duration.ofSeconds(60)), |
| 117 | + 2000L, |
| 118 | + "Wait for the JobResult being written to the JobResultStore."); |
| 119 | + |
| 120 | + final S3ObjectSummary objRef = Iterables.getOnlyElement(getObjectsFromJobResultStore()); |
| 121 | + assertThat(objRef.getKey()) |
| 122 | + .matches(FileSystemJobResultStore::hasValidJobResultStoreEntryExtension) |
| 123 | + .matches(not(FileSystemJobResultStore::hasValidDirtyJobResultStoreEntryExtension)); |
| 124 | + |
| 125 | + final String objContent = |
| 126 | + getMinioContainer() |
| 127 | + .getClient() |
| 128 | + .getObjectAsString(objRef.getBucketName(), objRef.getKey()); |
| 129 | + assertThat(objContent).contains(ApplicationStatus.SUCCEEDED.name()); |
| 130 | + } |
| 131 | +} |
0 commit comments