Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -865,7 +867,7 @@ private Optional<RemoteHostEndPoint> 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()) {
Expand All @@ -892,21 +894,16 @@ private Optional<RemoteHostEndPoint> getLinstorEP(DevelopersApi api, String rscN
}

private Optional<RemoteHostEndPoint> 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<com.linbit.linstor.api.model.StoragePool> 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();
}

Expand Down Expand Up @@ -958,9 +955,11 @@ private Answer copyTemplate(DataObject srcData, DataObject dstData) {
}
else {
answer = new Answer(cmd, false, "Unable to get matching Linstor endpoint.");
deleteResourceDefinition(pool, rscName);
}
} catch (ApiException exc) {
s_logger.error("copy template failed: ", exc);
deleteResourceDefinition(pool, rscName);
throw new CloudRuntimeException(exc.getBestMessage());
}
return answer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ public static List<String> 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<com.linbit.linstor.api.model.StoragePool>
getDiskfulStoragePools(@Nonnull DevelopersApi api, @Nonnull String rscName) throws ApiException
{
List<ResourceWithVolumes> 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;
Expand All @@ -107,13 +107,23 @@ public static List<String> getLinstorNodeNames(@Nonnull DevelopersApi api) throw
}

List<com.linbit.linstor.api.model.StoragePool> 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<com.linbit.linstor.api.model.StoragePool> sps = getDiskfulStoragePools(api, rscName);
if (sps != null) {
Copy link
Copy Markdown
Contributor

@sureshanaparti sureshanaparti Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (sps != null) {
if (sps != null && !sps.isEmpty()) {

or use CollectionUtils.isNotEmpty(sps)

and
return sps.get(0)

return !sps.isEmpty() ? sps.get(0) : null;
}
return null;
}

public static String getSnapshotPath(com.linbit.linstor.api.model.StoragePool sp, String rscName, String snapshotName) {
Expand Down