sureshanaparti commented on a change in pull request #4994:
URL: https://github.com/apache/cloudstack/pull/4994#discussion_r626285546



##########
File path: 
plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java
##########
@@ -0,0 +1,420 @@
+// 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.datastore.driver;
+
+import com.linbit.linstor.api.ApiCallChecker;
+import com.linbit.linstor.api.ApiException;
+import com.linbit.linstor.api.DevelopersApi;
+import com.linbit.linstor.api.model.ApiCallRc;
+import com.linbit.linstor.api.model.ApiCallRcList;
+import com.linbit.linstor.api.model.ResourceGroupSpawn;
+import com.linbit.linstor.api.model.ResourceWithVolumes;
+import com.linbit.linstor.api.model.VolumeDefinitionModify;
+
+import javax.inject.Inject;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.to.DataObjectType;
+import com.cloud.agent.api.to.DataStoreTO;
+import com.cloud.agent.api.to.DataTO;
+import com.cloud.host.Host;
+import com.cloud.storage.ResizeVolumePayload;
+import com.cloud.storage.StoragePool;
+import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.utils.Pair;
+import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
+import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
+import 
org.apache.cloudstack.engine.subsystem.api.storage.DataStoreCapabilities;
+import 
org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
+import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
+import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
+import org.apache.cloudstack.storage.command.CommandResult;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.storage.datastore.util.LinstorUtil;
+import org.apache.cloudstack.storage.volume.VolumeObject;
+import org.apache.log4j.Logger;
+
+public class LinstorPrimaryDataStoreDriverImpl implements 
PrimaryDataStoreDriver {
+    private static final Logger s_logger = 
Logger.getLogger(LinstorPrimaryDataStoreDriverImpl.class);
+    @Inject
+    private PrimaryDataStoreDao _storagePoolDao;
+    @Inject
+    private VolumeDao _volumeDao;
+
+    public LinstorPrimaryDataStoreDriverImpl()
+    {
+    }
+
+    @Override
+    public Map<String, String> getCapabilities()
+    {
+        Map<String, String> mapCapabilities = new HashMap<>();
+
+        // Linstor can create a volume from a volume via snapshot restore, but 
this would only work
+        // if a LVM-thin storage pool is used, TBH it would also work with ZFS 
pools, but there you always
+        // have to keep in mind the child-parent snapshot relationship
+        // So we will rely on a plain copy volume mechanism which is more 
robust for now
+        
mapCapabilities.put(DataStoreCapabilities.CAN_CREATE_VOLUME_FROM_VOLUME.toString(),
 Boolean.FALSE.toString());
+
+        // for now, technically possible
+        
mapCapabilities.put(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString(), 
Boolean.FALSE.toString());
+        // CAN_CREATE_VOLUME_FROM_SNAPSHOT see note from 
CAN_CREATE_VOLUME_FROM_VOLUME
+        
mapCapabilities.put(DataStoreCapabilities.CAN_CREATE_VOLUME_FROM_SNAPSHOT.toString(),
 Boolean.FALSE.toString());
+        
mapCapabilities.put(DataStoreCapabilities.CAN_REVERT_VOLUME_TO_SNAPSHOT.toString(),
 Boolean.FALSE.toString());
+
+        
mapCapabilities.put(DataStoreCapabilities.VOLUME_SNAPSHOT_QUIESCEVM.toString(), 
Boolean.FALSE.toString());
+
+        return mapCapabilities;
+    }
+
+    @Override
+    public DataTO getTO(DataObject data)
+    {
+        return null;
+    }
+
+    @Override
+    public DataStoreTO getStoreTO(DataStore store)
+    {
+        return null;
+    }
+
+    @Override
+    public ChapInfo getChapInfo(DataObject dataObject)
+    {
+        return null;
+    }
+
+    @Override
+    public boolean grantAccess(DataObject dataObject, Host host, DataStore 
dataStore)
+    {
+        return false;
+    }
+
+    @Override
+    public void revokeAccess(DataObject dataObject, Host host, DataStore 
dataStore)
+    {
+    }
+
+    @Override
+    public long getUsedBytes(StoragePool storagePool)
+    {
+        return 0;
+    }
+
+    @Override
+    public long getUsedIops(StoragePool storagePool)
+    {
+        return 0;
+    }
+
+    @Override
+    public long getDataObjectSizeIncludingHypervisorSnapshotReserve(DataObject 
dataObject, StoragePool pool)
+    {
+        return dataObject.getSize();
+    }
+
+    @Override
+    public long getBytesRequiredForTemplate(TemplateInfo templateInfo, 
StoragePool storagePool)
+    {
+        return 0;
+    }
+
+    private void deleteResourceDefinition(DataStore dataStore, String 
rscDefName)
+    {
+        StoragePoolVO storagePool = 
_storagePoolDao.findById(dataStore.getId());
+        DevelopersApi linstorApi = 
LinstorUtil.getLinstorAPI(storagePool.getHostAddress());
+
+        try
+        {
+            ApiCallRcList answers = 
linstorApi.resourceDefinitionDelete(rscDefName);
+            if (ApiCallChecker.hasError(answers))
+            {
+                for (ApiCallRc answer : answers)
+                {
+                    s_logger.error(answer.getMessage());
+                }
+                throw new CloudRuntimeException("Linstor: Unable to delete 
resource definition: " + rscDefName);
+            }
+        } catch (ApiException apiEx)
+        {
+            s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
+            throw new CloudRuntimeException(apiEx);
+        }
+    }
+
+    @Override
+    public void deleteAsync(
+        DataStore dataStore,
+        DataObject dataObject,
+        AsyncCompletionCallback<CommandResult> callback)
+    {
+        s_logger.debug("deleteAsync: " + dataObject.getType() + ";" + 
dataObject.getId());
+        String errMsg = null;
+
+        StoragePoolVO storagePool = 
_storagePoolDao.findById(dataStore.getId());
+
+        if (dataObject.getType() == DataObjectType.VOLUME)
+        {
+            VolumeInfo volumeInfo = (VolumeInfo) dataObject;
+
+            long storagePoolId = dataStore.getId();
+            final String rscName = "cs-" + volumeInfo.getPath();

Review comment:
       Better to define the prefix "_cs-_" as string constant in some common 
class, and use it across.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to