abh1sar commented on code in PR #9208:
URL: https://github.com/apache/cloudstack/pull/9208#discussion_r1708188738


##########
server/src/main/java/org/apache/cloudstack/storage/fileshare/FileShareServiceImpl.java:
##########
@@ -0,0 +1,687 @@
+// 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.cloudstack.storage.fileshare;
+
+import static 
org.apache.cloudstack.storage.fileshare.FileShare.FileShareCleanupDelay;
+import static 
org.apache.cloudstack.storage.fileshare.FileShare.FileShareCleanupInterval;
+import static 
org.apache.cloudstack.storage.fileshare.FileShare.FileShareFeatureEnabled;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import com.cloud.configuration.ConfigurationManager;
+import com.cloud.dc.DataCenter;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.OperationTimedoutException;
+import com.cloud.exception.PermissionDeniedException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.org.Grouping;
+import com.cloud.projects.Project;
+import com.cloud.storage.DiskOfferingVO;
+import com.cloud.storage.VolumeApiService;
+import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.DiskOfferingDao;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.Pair;
+import com.cloud.utils.Ternary;
+import com.cloud.utils.concurrency.NamedThreadFactory;
+import com.cloud.utils.db.EntityManager;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GlobalLock;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.fsm.NoTransitionException;
+import com.cloud.utils.fsm.StateMachine2;
+
+import org.apache.cloudstack.api.ResponseObject;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.ChangeFileShareDiskOfferingCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.ChangeFileShareServiceOfferingCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.CreateFileShareCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.ExpungeFileShareCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.ListFileShareProvidersCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.ListFileSharesCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.DestroyFileShareCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.RecoverFileShareCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.RestartFileShareCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.StartFileShareCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.StopFileShareCmd;
+import 
org.apache.cloudstack.api.command.user.storage.fileshare.UpdateFileShareCmd;
+import org.apache.cloudstack.api.response.FileShareResponse;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
+import org.apache.cloudstack.storage.fileshare.dao.FileShareDao;
+import org.apache.cloudstack.storage.fileshare.FileShare.Event;
+import org.apache.cloudstack.storage.fileshare.FileShare.State;
+import org.apache.cloudstack.storage.fileshare.query.dao.FileShareJoinDao;
+import org.apache.cloudstack.storage.fileshare.query.vo.FileShareJoinVO;
+
+import com.cloud.event.ActionEvent;
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class FileShareServiceImpl extends ManagerBase implements 
FileShareService, Configurable {
+
+    @Inject
+    private AccountManager accountMgr;
+
+    @Inject
+    private EntityManager entityMgr;
+
+    @Inject
+    private ConfigurationManager configMgr;
+
+    @Inject
+    private VolumeApiService volumeApiService;
+
+    @Inject
+    private FileShareDao fileShareDao;
+
+    @Inject
+    private FileShareJoinDao fileShareJoinDao;
+
+    @Inject
+    private DiskOfferingDao diskOfferingDao;
+
+    @Inject
+    ConfigurationDao configDao;
+
+    @Inject
+    VolumeDao volumeDao;
+
+    protected List<FileShareProvider> fileShareProviders;
+
+    private Map<String, FileShareProvider> fileShareProviderMap = new 
HashMap<>();
+
+    private final StateMachine2<State, Event, FileShare> fileShareStateMachine;
+
+    ScheduledExecutorService _executor = null;
+
+    public FileShareServiceImpl() {
+        this.fileShareStateMachine = State.getStateMachine();
+    }
+
+    @Override
+    public boolean start() {
+        fileShareProviderMap.clear();
+        for (final FileShareProvider provider : fileShareProviders) {
+            fileShareProviderMap.put(provider.getName(), provider);
+            provider.configure();
+        }
+        _executor.scheduleWithFixedDelay(new FileShareGarbageCollector(), 
FileShareCleanupInterval.value(), FileShareCleanupInterval.value(), 
TimeUnit.SECONDS);
+        return true;
+    }
+
+    public boolean stop() {
+        _executor.shutdown();
+        return true;
+    }
+
+    @Override
+    public List<FileShareProvider> getFileShareProviders() {
+        return fileShareProviders;
+    }
+
+    @Override
+    public boolean stateTransitTo(FileShare fileShare, Event event) {
+        try {
+            return fileShareStateMachine.transitTo(fileShare, event, null, 
fileShareDao);
+        } catch (NoTransitionException e) {
+            logger.debug(String.format("Failed during event % for File Share 
%s [%s] due to exception %",
+                    event.toString(), fileShare.getName(), fileShare.getId(), 
e));
+            return false;
+        }
+    }
+
+    @Override
+    public void setFileShareProviders(List<FileShareProvider> 
fileShareProviders) {
+        this.fileShareProviders = fileShareProviders;
+    }
+
+    @Override
+    public FileShareProvider getFileShareProvider(String 
fileShareProviderName) {
+        if (fileShareProviderMap.containsKey(fileShareProviderName)) {
+            return fileShareProviderMap.get(fileShareProviderName);
+        }
+        throw new CloudRuntimeException("Invalid file share provider name!");
+    }
+
+    @Override
+    public boolean configure(final String name, final Map<String, Object> 
params) throws ConfigurationException {
+        Map<String, String> configs = 
configDao.getConfiguration("management-server", params);
+        String workers = configs.get("expunge.workers");
+        int wrks = NumbersUtil.parseInt(workers, 10);

Review Comment:
   yes, I can add a new fileshare specific fileshare.expunge.workers setting



-- 
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]

Reply via email to