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


##########
plugins/storage/fileshare/storagefsvm/src/main/java/org/apache/cloudstack/storage/fileshare/lifecycle/StorageFsVmFileShareLifeCycle.java:
##########
@@ -0,0 +1,313 @@
+// 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.lifecycle;
+
+import static 
org.apache.cloudstack.storage.fileshare.FileShare.FileShareVmNamePrefix;
+import static 
org.apache.cloudstack.storage.fileshare.provider.StorageFsVmFileShareProvider.STORAGEFSVM_MIN_CPU_COUNT;
+import static 
org.apache.cloudstack.storage.fileshare.provider.StorageFsVmFileShareProvider.STORAGEFSVM_MIN_RAM_SIZE;
+
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.OperationTimedoutException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.storage.LaunchPermissionVO;
+import com.cloud.storage.Volume;
+import com.cloud.storage.VolumeApiService;
+import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.LaunchPermissionDao;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.uservm.UserVm;
+import com.cloud.utils.FileUtil;
+import com.cloud.utils.Pair;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.utils.net.NetUtils;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.UserVmManager;
+import com.cloud.vm.UserVmService;
+import com.cloud.vm.UserVmVO;
+import com.cloud.vm.dao.NicDao;
+import com.cloud.vm.dao.UserVmDao;
+
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.storage.fileshare.FileShare;
+import org.apache.cloudstack.storage.fileshare.FileShareLifeCycle;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.network.Network;
+import com.cloud.resource.ResourceManager;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachineManager;
+
+public class StorageFsVmFileShareLifeCycle implements FileShareLifeCycle {
+    protected Logger logger = LogManager.getLogger(getClass());
+
+    @Inject
+    private AccountManager accountMgr;
+
+    @Inject
+    protected ResourceManager resourceMgr;
+
+    @Inject
+    private VirtualMachineManager virtualMachineManager;
+
+    @Inject
+    private VolumeApiService volumeApiService;
+
+    @Inject
+    protected UserVmService userVmService;
+
+    @Inject
+    protected UserVmManager userVmManager;
+
+    @Inject
+    private DataCenterDao dataCenterDao;
+
+    @Inject
+    private VMTemplateDao templateDao;
+
+    @Inject
+    VolumeDao volumeDao;
+
+    @Inject
+    private UserVmDao userVmDao;
+
+    @Inject
+    NicDao nicDao;
+
+    @Inject
+    ServiceOfferingDao serviceOfferingDao;
+
+    @Inject
+    protected LaunchPermissionDao launchPermissionDao;
+
+    private String readResourceFile(String resource) {
+        try {
+            return FileUtil.readResourceFile(resource);
+        } catch (IOException e) {
+            throw new CloudRuntimeException("Unable to read the user data 
resource file due to exception " + e.getMessage());
+        }
+    }
+
+    private String getStorageFsVmConfig(final String fileSystem, final String 
hypervisorType) {
+        String fsVmConfig = readResourceFile("/conf/fsvm-init.yml");
+        final String filesystem = "{{ fsvm.filesystem }}";
+        final String hypervisor = "{{ fsvm.hypervisor }}";
+        fsVmConfig = fsVmConfig.replace(filesystem, fileSystem);
+        fsVmConfig = fsVmConfig.replace(hypervisor, hypervisorType);
+        return fsVmConfig;
+    }
+
+    private String getStorageFsVmName(String fileShareName) {
+        String prefix = String.format("%s-%s", FileShareVmNamePrefix, 
fileShareName);
+        String suffix = Long.toHexString(System.currentTimeMillis());
+
+        if (!NetUtils.verifyDomainNameLabel(prefix, true)) {
+            prefix = prefix.replaceAll("[^a-zA-Z0-9-]", "");
+        }
+        int nameLength = prefix.length() + suffix.length() + 
FileShareVmNamePrefix.length();
+        if (nameLength > 63) {
+            int prefixLength = prefix.length() - (nameLength - 63);
+            prefix = prefix.substring(0, prefixLength);
+        }
+        return (String.format("%s-%s", prefix, suffix));
+    }
+
+    private UserVm createFileShareVM(Long zoneId, Account owner, List<Long> 
networkIds, String name, Long serviceOfferingId, Long diskOfferingId, 
FileShare.FileSystemType fileSystem, Long size, Long minIops, Long maxIops) 
throws ResourceUnavailableException, InsufficientCapacityException, 
ResourceAllocationException {
+        ServiceOffering serviceOffering = 
serviceOfferingDao.findById(serviceOfferingId);
+
+        DataCenter zone = dataCenterDao.findById(zoneId);
+        Hypervisor.HypervisorType availableHypervisor = 
resourceMgr.getAvailableHypervisor(zoneId);

Review Comment:
   @abh1sar can you please check behaviour with a multi-hypervisor env where 
the default hypervisor gets out of capacity?
   
   I feel we should
   - get the list of all available hypervisors and iterate over them
   - check if the required template is present
   - check if a deployment plan is possible



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