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 @@ -30,14 +30,18 @@ public class ModifyStoragePoolAnswer extends Answer {
private Map<String, TemplateProp> templateInfo;
private String localDatastoreName;
private String poolType;
private List<ModifyStoragePoolAnswer> datastoreClusterChildren = new ArrayList<>();;
private List<ModifyStoragePoolAnswer> datastoreClusterChildren = new ArrayList<>();

public ModifyStoragePoolAnswer(ModifyStoragePoolCommand cmd, long capacityBytes, long availableBytes, Map<String, TemplateProp> tInfo) {
this(cmd, capacityBytes, availableBytes, tInfo, null);
}

public ModifyStoragePoolAnswer(ModifyStoragePoolCommand cmd, long capacityBytes, long availableBytes, Map<String, TemplateProp> tInfo, Map<String, String> details) {
super(cmd);

result = true;

poolInfo = new StoragePoolInfo(null, cmd.getPool().getHost(), cmd.getPool().getPath(), cmd.getLocalPath(), cmd.getPool().getType(), capacityBytes, availableBytes);
poolInfo = new StoragePoolInfo(null, cmd.getPool().getHost(), cmd.getPool().getPath(), cmd.getLocalPath(), cmd.getPool().getType(), capacityBytes, availableBytes, details);

templateInfo = tInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.cloud.agent.api;

import java.io.File;
import java.util.Map;
import java.util.UUID;

import com.cloud.agent.api.to.StorageFilerTO;
Expand All @@ -32,13 +33,19 @@ public class ModifyStoragePoolCommand extends Command {
private StorageFilerTO pool;
private String localPath;
private String storagePath;
private Map<String, String> details;

public ModifyStoragePoolCommand(boolean add, StoragePool pool, String localPath) {
this.add = add;
this.pool = new StorageFilerTO(pool);
this.localPath = localPath;
}

public ModifyStoragePoolCommand(boolean add, StoragePool pool, String localPath, Map<String, String> details) {
this(add, pool, localPath);
this.details = details;
}

public ModifyStoragePoolCommand(boolean add, StoragePool pool) {
this(add, pool, LOCAL_PATH_PREFIX + File.separator + UUID.nameUUIDFromBytes((pool.getHostAddress() + pool.getPath()).getBytes()));
}
Expand Down Expand Up @@ -67,6 +74,14 @@ public String getStoragePath() {
return storagePath;
}

public void setDetails(Map<String, String> details) {
this.details = details;
}

public Map<String, String> getDetails() {
return details;
}

@Override
public boolean executeInSequence() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public interface StorageManager extends StorageService {

boolean registerHostListener(String providerUuid, HypervisorHostListener listener);

void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException;
boolean connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException;

void disconnectHostFromSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public Answer execute(final ModifyStoragePoolCommand command, final LibvirtCompu
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
final KVMStoragePool storagepool =
storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType());
.getUserInfo(), command.getPool().getType(), command.getDetails());
if (storagepool == null) {
return new Answer(command, false, " Failed to create storage pool");
}

final Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, storagepool.getCapacity(), storagepool.getAvailable(), tInfo);
final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, storagepool.getCapacity(), storagepool.getAvailable(), tInfo, storagepool.getDetails());

return answer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor {
private static final Map<String, KVMStoragePool> MapStorageUuidToStoragePool = new HashMap<>();

@Override
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType) {
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType, Map<String, String> details) {
IscsiAdmStoragePool storagePool = new IscsiAdmStoragePool(uuid, host, port, storagePoolType, this);

MapStorageUuidToStoragePool.put(uuid, storagePool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ public boolean supportsConfigDriveIso() {
return false;
}

@Override
public Map<String, String> getDetails() {
return null;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.JSON_STYLE).append("uuid", getUuid()).append("path", getLocalPath()).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ public interface KVMStoragePool {
public boolean createFolder(String path);

public boolean supportsConfigDriveIso();

public Map<String, String> getDetails();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ private class StoragePoolInformation {
String userInfo;
boolean type;
StoragePoolType poolType;
Map<String, String> details;

public StoragePoolInformation(String name, String host, int port, String path, String userInfo, StoragePoolType poolType, boolean type) {
public StoragePoolInformation(String name, String host, int port, String path, String userInfo, StoragePoolType poolType, Map<String, String> details, boolean type) {
this.name = name;
this.host = host;
this.port = port;
this.path = path;
this.userInfo = userInfo;
this.type = type;
this.poolType = poolType;
this.details = details;
}
}

Expand Down Expand Up @@ -270,7 +272,7 @@ public KVMStoragePool getStoragePool(StoragePoolType type, String uuid, boolean
} catch (Exception e) {
StoragePoolInformation info = _storagePools.get(uuid);
if (info != null) {
pool = createStoragePool(info.name, info.host, info.port, info.path, info.userInfo, info.poolType, info.type);
pool = createStoragePool(info.name, info.host, info.port, info.path, info.userInfo, info.poolType, info.details, info.type);
} else {
throw new CloudRuntimeException("Could not fetch storage pool " + uuid + " from libvirt due to " + e.getMessage());
}
Expand Down Expand Up @@ -300,7 +302,7 @@ public KVMStoragePool getStoragePoolByURI(String uri) {
}

// secondary storage registers itself through here
return createStoragePool(uuid, sourceHost, 0, sourcePath, "", protocol, false);
return createStoragePool(uuid, sourceHost, 0, sourcePath, "", protocol, null, false);
}

public KVMPhysicalDisk getPhysicalDisk(StoragePoolType type, String poolUuid, String volName) {
Expand Down Expand Up @@ -341,20 +343,27 @@ public KVMPhysicalDisk getPhysicalDisk(StoragePoolType type, String poolUuid, St

public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type) {
// primary storage registers itself through here
return createStoragePool(name, host, port, path, userInfo, type, true);
return createStoragePool(name, host, port, path, userInfo, type, null, true);
}

/**
* Primary Storage registers itself through here
*/
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details) {
return createStoragePool(name, host, port, path, userInfo, type, details, true);
}

//Note: due to bug CLOUDSTACK-4459, createStoragepool can be called in parallel, so need to be synced.
private synchronized KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, boolean primaryStorage) {
private synchronized KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details, boolean primaryStorage) {
StorageAdaptor adaptor = getStorageAdaptor(type);
KVMStoragePool pool = adaptor.createStoragePool(name, host, port, path, userInfo, type);
KVMStoragePool pool = adaptor.createStoragePool(name, host, port, path, userInfo, type, details);

// LibvirtStorageAdaptor-specific statement
if (type == StoragePoolType.NetworkFilesystem && primaryStorage) {
KVMHABase.NfsStoragePool nfspool = new KVMHABase.NfsStoragePool(pool.getUuid(), host, path, pool.getLocalPath(), PoolType.PrimaryStorage);
_haMonitor.addStoragePool(nfspool);
}
StoragePoolInformation info = new StoragePoolInformation(name, host, port, path, userInfo, type, primaryStorage);
StoragePoolInformation info = new StoragePoolInformation(name, host, port, path, userInfo, type, details, primaryStorage);
addStoragePool(pool.getUuid(), info);
return pool;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
}

@Override
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type) {
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details) {
s_logger.info("Attempting to create storage pool " + name + " (" + type.toString() + ") in libvirt");

StoragePool sp = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ public boolean supportsConfigDriveIso() {
return false;
}

@Override
public Map<String, String> getDetails() {
return null;
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.JSON_STYLE).append("uuid", getUuid()).append("path", getLocalPath()).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool)

@Override
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo,
Storage.StoragePoolType type)
Storage.StoragePoolType type, Map<String, String> details)
{
s_logger.debug(String.format(
"Linstor createStoragePool: name: '%s', host: '%s', path: %s, userinfo: %s", name, host, path, userInfo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public boolean supportsConfigDriveIso()
return false;
}

@Override
public Map<String, String> getDetails() {
return null;
}

public String getResourceGroup() {
return _resourceGroup;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ManagedNfsStorageAdaptor(StorageLayer storagelayer) {
}

@Override
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType) {
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType, Map<String, String> details) {

LibvirtStoragePool storagePool = new LibvirtStoragePool(uuid, path, StoragePoolType.ManagedNFS, this, null);
storagePool.setSourceHost(host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public KVMPhysicalDisk getPhysicalDisk(String volumePath, KVMStoragePool pool) {
}

@Override
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, Storage.StoragePoolType type) {
ScaleIOStoragePool storagePool = new ScaleIOStoragePool(uuid, host, port, path, type, this);
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, Storage.StoragePoolType type, Map<String, String> details) {
ScaleIOStoragePool storagePool = new ScaleIOStoragePool(uuid, host, port, path, type, details, this);
MapStorageUuidToStoragePool.put(uuid, storagePool);
return storagePool;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.Map;

import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil;
import org.apache.cloudstack.utils.qemu.QemuImg;

import com.cloud.storage.Storage;
Expand All @@ -34,8 +36,9 @@ public class ScaleIOStoragePool implements KVMStoragePool {
private long capacity;
private long used;
private long available;
private Map<String, String> details;

public ScaleIOStoragePool(String uuid, String host, int port, String path, Storage.StoragePoolType poolType, StorageAdaptor adaptor) {
public ScaleIOStoragePool(String uuid, String host, int port, String path, Storage.StoragePoolType poolType, Map<String, String> poolDetails, StorageAdaptor adaptor) {
this.uuid = uuid;
sourceHost = host;
sourcePort = port;
Expand All @@ -45,6 +48,25 @@ public ScaleIOStoragePool(String uuid, String host, int port, String path, Stora
capacity = 0;
used = 0;
available = 0;
details = poolDetails;
addSDCDetails();
}

private void addSDCDetails() {
if (details == null || !details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)) {
return;
}

String storageSystemId = details.get(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID);
String sdcId = ScaleIOUtil.getSdcId(storageSystemId);
if (sdcId != null) {
details.put(ScaleIOGatewayClient.SDC_ID, sdcId);
} else {
String sdcGuId = ScaleIOUtil.getSdcGuid();
if (sdcGuId != null) {
details.put(ScaleIOGatewayClient.SDC_GUID, sdcGuId);
}
}
}

@Override
Expand Down Expand Up @@ -178,4 +200,9 @@ public boolean createFolder(String path) {
public boolean supportsConfigDriveIso() {
return false;
}

@Override
public Map<String, String> getDetails() {
return this.details;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface StorageAdaptor {
// it with info from local disk, and return it
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool);

public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type);
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details);

public boolean deleteStoragePool(String uuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2765,10 +2765,9 @@ public void testModifyStoragePoolCommand() {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final KVMStoragePool kvmStoragePool = Mockito.mock(KVMStoragePool.class);


when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType())).thenReturn(kvmStoragePool);
.getUserInfo(), command.getPool().getType(), command.getDetails())).thenReturn(kvmStoragePool);


final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
Expand All @@ -2779,7 +2778,7 @@ public void testModifyStoragePoolCommand() {

verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType());
.getUserInfo(), command.getPool().getType(), command.getDetails());
}

@Test
Expand All @@ -2791,7 +2790,7 @@ public void testModifyStoragePoolCommandFailure() {

when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType())).thenReturn(null);
.getUserInfo(), command.getPool().getType(), command.getDetails())).thenReturn(null);


final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
Expand All @@ -2802,7 +2801,7 @@ public void testModifyStoragePoolCommandFailure() {

verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType());
.getUserInfo(), command.getPool().getType(), command.getDetails());
}

@Test
Expand Down
Loading