diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java index 6f8246728b11..328b3d21d0a1 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java @@ -59,6 +59,7 @@ import com.cloud.configuration.Config; import com.cloud.host.Host; import com.cloud.host.dao.HostDao; +import com.cloud.resource.ResourceState; import com.cloud.storage.DataStoreRole; import com.cloud.storage.ResizeVolumePayload; import com.cloud.storage.SnapshotVO; @@ -214,6 +215,7 @@ private void deleteResourceDefinition(StoragePoolVO storagePoolVO, String rscDef } throw new CloudRuntimeException("Linstor: Unable to delete resource definition: " + rscDefName); } + s_logger.info(String.format("Linstor: Deleted resource %s", rscDefName)); } catch (ApiException apiEx) { s_logger.error("Linstor: ApiEx - " + apiEx.getMessage()); @@ -865,7 +867,7 @@ private Optional getLinstorEP(DevelopersApi api, String rscN Host host = null; for (String nodeName : linstorNodeNames) { host = _hostDao.findByName(nodeName); - if (host != null) { + if (host != null && host.getResourceState() == ResourceState.Enabled) { s_logger.info(String.format("Linstor: Make resource %s available on node %s ...", rscName, nodeName)); ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, nodeName, new ResourceMakeAvailable()); if (!answers.hasError()) { @@ -892,21 +894,16 @@ private Optional getLinstorEP(DevelopersApi api, String rscN } private Optional getDiskfullEP(DevelopersApi api, String rscName) throws ApiException { - com.linbit.linstor.api.model.StoragePool linSP = - LinstorUtil.getDiskfulStoragePool(api, rscName); - if (linSP != null) - { - Host host = _hostDao.findByName(linSP.getNodeName()); - if (host == null) - { - s_logger.error("Linstor: Host '" + linSP.getNodeName() + "' not found."); - return Optional.empty(); - } - else - { - return Optional.of(RemoteHostEndPoint.getHypervisorHostEndPoint(host)); + List linSPs = LinstorUtil.getDiskfulStoragePools(api, rscName); + if (linSPs != null) { + for (com.linbit.linstor.api.model.StoragePool sp : linSPs) { + Host host = _hostDao.findByName(sp.getNodeName()); + if (host != null && host.getResourceState() == ResourceState.Enabled) { + return Optional.of(RemoteHostEndPoint.getHypervisorHostEndPoint(host)); + } } } + s_logger.error("Linstor: No diskfull host found."); return Optional.empty(); } @@ -962,7 +959,6 @@ private Answer copyTemplate(DataObject srcData, DataObject dstData) { } } catch (ApiException exc) { s_logger.error("copy template failed: ", exc); - s_logger.info(String.format("deleting failed template resource: %s", rscName)); deleteResourceDefinition(pool, rscName); throw new CloudRuntimeException(exc.getBestMessage()); } diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java index e953c94db220..33cbea0996d5 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java @@ -77,16 +77,16 @@ public static List getLinstorNodeNames(@Nonnull DevelopersApi api) throw return nodes.stream().map(Node::getName).collect(Collectors.toList()); } - public static com.linbit.linstor.api.model.StoragePool - getDiskfulStoragePool(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException + public static List + getDiskfulStoragePools(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException { List resources = api.viewResources( - Collections.emptyList(), - Collections.singletonList(rscName), - Collections.emptyList(), - Collections.emptyList(), - null, - null); + Collections.emptyList(), + Collections.singletonList(rscName), + Collections.emptyList(), + Collections.emptyList(), + null, + null); String nodeName = null; String storagePoolName = null; @@ -107,13 +107,23 @@ public static List getLinstorNodeNames(@Nonnull DevelopersApi api) throw } List sps = api.viewStoragePools( - Collections.singletonList(nodeName), - Collections.singletonList(storagePoolName), - Collections.emptyList(), - null, - null + Collections.singletonList(nodeName), + Collections.singletonList(storagePoolName), + Collections.emptyList(), + null, + null ); - return !sps.isEmpty() ? sps.get(0) : null; + return sps != null ? sps : Collections.emptyList(); + } + + public static com.linbit.linstor.api.model.StoragePool + getDiskfulStoragePool(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException + { + List sps = getDiskfulStoragePools(api, rscName); + if (sps != null) { + return !sps.isEmpty() ? sps.get(0) : null; + } + return null; } public static String getSnapshotPath(com.linbit.linstor.api.model.StoragePool sp, String rscName, String snapshotName) {