From 463967abb08cbf1904f9e4a6eaf11554ba742c52 Mon Sep 17 00:00:00 2001 From: Denghui Dong Date: Tue, 17 Oct 2023 16:51:32 +0800 Subject: [PATCH] chore: move StorageAccessible out of StorageServiceImpl --- .../eclipse/jifa/server/Configuration.java | 1 - .../server/condition/StorageAccessible.java | 33 +++++++++++++++++++ .../controller/ElasticWorkerController.java | 1 - .../service/impl/StorageServiceImpl.java | 24 ++------------ .../task/ElasticWorkerRelatedTasks.java | 1 - .../jifa/server/task/StorageRelatedTasks.java | 5 +-- 6 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 server/src/main/java/org/eclipse/jifa/server/condition/StorageAccessible.java diff --git a/server/src/main/java/org/eclipse/jifa/server/Configuration.java b/server/src/main/java/org/eclipse/jifa/server/Configuration.java index dc01fb7f..5be58302 100644 --- a/server/src/main/java/org/eclipse/jifa/server/Configuration.java +++ b/server/src/main/java/org/eclipse/jifa/server/Configuration.java @@ -16,7 +16,6 @@ import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Positive; -import jakarta.validation.constraints.PositiveOrZero; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; diff --git a/server/src/main/java/org/eclipse/jifa/server/condition/StorageAccessible.java b/server/src/main/java/org/eclipse/jifa/server/condition/StorageAccessible.java new file mode 100644 index 00000000..e5b18a04 --- /dev/null +++ b/server/src/main/java/org/eclipse/jifa/server/condition/StorageAccessible.java @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ +package org.eclipse.jifa.server.condition; + +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; + +public class StorageAccessible extends AnyNestedCondition { + + public StorageAccessible() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @SuppressWarnings("unused") + @Master + @ElasticSchedulingStrategy + static class MasterWithElasticSchedulingStrategy { + } + + @SuppressWarnings("unused") + @org.eclipse.jifa.server.condition.Worker + static class Worker { + } +} diff --git a/server/src/main/java/org/eclipse/jifa/server/controller/ElasticWorkerController.java b/server/src/main/java/org/eclipse/jifa/server/controller/ElasticWorkerController.java index f04cac8a..3477a1da 100644 --- a/server/src/main/java/org/eclipse/jifa/server/controller/ElasticWorkerController.java +++ b/server/src/main/java/org/eclipse/jifa/server/controller/ElasticWorkerController.java @@ -29,7 +29,6 @@ public class ElasticWorkerController { private final WorkerService workerService; - @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") public ElasticWorkerController(WorkerService workerService) { this.workerService = workerService; } diff --git a/server/src/main/java/org/eclipse/jifa/server/service/impl/StorageServiceImpl.java b/server/src/main/java/org/eclipse/jifa/server/service/impl/StorageServiceImpl.java index 975e54f2..c8a15be2 100644 --- a/server/src/main/java/org/eclipse/jifa/server/service/impl/StorageServiceImpl.java +++ b/server/src/main/java/org/eclipse/jifa/server/service/impl/StorageServiceImpl.java @@ -41,13 +41,11 @@ import org.eclipse.jifa.common.util.ExecutorFactory; import org.eclipse.jifa.common.util.Validate; import org.eclipse.jifa.server.ConfigurationAccessor; -import org.eclipse.jifa.server.condition.ElasticSchedulingStrategy; -import org.eclipse.jifa.server.condition.Master; +import org.eclipse.jifa.server.condition.StorageAccessible; import org.eclipse.jifa.server.domain.dto.FileTransferRequest; import org.eclipse.jifa.server.enums.FileType; import org.eclipse.jifa.server.service.StorageService; import org.eclipse.jifa.server.support.FileTransferListener; -import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -70,28 +68,10 @@ import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicLong; -@Conditional(StorageServiceImpl.Accessible.class) +@Conditional(StorageAccessible.class) @Service public class StorageServiceImpl extends ConfigurationAccessor implements StorageService { - static class Accessible extends AnyNestedCondition { - - public Accessible() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @SuppressWarnings("unused") - @Master - @ElasticSchedulingStrategy - static class MasterWithElasticSchedulingStrategy { - } - - @SuppressWarnings("unused") - @org.eclipse.jifa.server.condition.Worker - static class Worker { - } - } - private Executor executor; private Path basePath; diff --git a/server/src/main/java/org/eclipse/jifa/server/task/ElasticWorkerRelatedTasks.java b/server/src/main/java/org/eclipse/jifa/server/task/ElasticWorkerRelatedTasks.java index 44f342c4..2fc2d4df 100644 --- a/server/src/main/java/org/eclipse/jifa/server/task/ElasticWorkerRelatedTasks.java +++ b/server/src/main/java/org/eclipse/jifa/server/task/ElasticWorkerRelatedTasks.java @@ -42,7 +42,6 @@ public class ElasticWorkerRelatedTasks extends ConfigurationAccessor { private final WorkerService workerService; - @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") public ElasticWorkerRelatedTasks(LockSupport lockSupport, ElasticWorkerRepo elasticWorkerRepo, ElasticWorkerScheduler elasticWorkerScheduler, WorkerService workerService) { diff --git a/server/src/main/java/org/eclipse/jifa/server/task/StorageRelatedTasks.java b/server/src/main/java/org/eclipse/jifa/server/task/StorageRelatedTasks.java index 0562db86..f3e86560 100644 --- a/server/src/main/java/org/eclipse/jifa/server/task/StorageRelatedTasks.java +++ b/server/src/main/java/org/eclipse/jifa/server/task/StorageRelatedTasks.java @@ -14,12 +14,13 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.jifa.server.ConfigurationAccessor; +import org.eclipse.jifa.server.condition.StorageAccessible; import org.eclipse.jifa.server.enums.FileType; import org.eclipse.jifa.server.repository.FileRepo; import org.eclipse.jifa.server.repository.TransferringFileRepo; import org.eclipse.jifa.server.service.FileService; import org.eclipse.jifa.server.service.StorageService; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.context.annotation.Conditional; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -28,7 +29,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; -@ConditionalOnBean(StorageService.class) +@Conditional(StorageAccessible.class) @Component @Slf4j public class StorageRelatedTasks extends ConfigurationAccessor {