use of com.cloud.storage.Storage.StoragePoolType in project cloudstack by apache.
the class KVMStoragePoolManager method getStoragePoolByURI.
public KVMStoragePool getStoragePoolByURI(String uri) {
URI storageUri = null;
try {
storageUri = new URI(uri);
} catch (URISyntaxException e) {
throw new CloudRuntimeException(e.toString());
}
String sourcePath = null;
String uuid = null;
String sourceHost = "";
StoragePoolType protocol = null;
if (storageUri.getScheme().equalsIgnoreCase("nfs")) {
sourcePath = storageUri.getPath();
sourcePath = sourcePath.replace("//", "/");
sourceHost = storageUri.getHost();
uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString();
protocol = StoragePoolType.NetworkFilesystem;
}
// secondary storage registers itself through here
return createStoragePool(uuid, sourceHost, 0, sourcePath, "", protocol, false);
}
use of com.cloud.storage.Storage.StoragePoolType in project cloudstack by apache.
the class LibvirtStoragePoolTest method testAttributes.
public void testAttributes() {
String uuid = "4c4fb08b-373e-4f30-a120-3aa3a43f31da";
String name = "myfirstpool";
StoragePoolType type = StoragePoolType.NetworkFilesystem;
StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
StoragePool storage = Mockito.mock(StoragePool.class);
LibvirtStoragePool pool = new LibvirtStoragePool(uuid, name, type, adapter, storage);
assertEquals(pool.getCapacity(), 0);
assertEquals(pool.getUsed(), 0);
assertEquals(pool.getName(), name);
assertEquals(pool.getUuid(), uuid);
assertEquals(pool.getAvailable(), 0);
assertEquals(pool.getStoragePoolType(), type);
pool.setCapacity(2048);
pool.setUsed(1024);
pool.setAvailable(1023);
assertEquals(pool.getCapacity(), 2048);
assertEquals(pool.getUsed(), 1024);
assertEquals(pool.getAvailable(), 1023);
}
use of com.cloud.storage.Storage.StoragePoolType in project cloudstack by apache.
the class CloudStackPrimaryDataStoreLifeCycleImpl method initialize.
@SuppressWarnings("unchecked")
@Override
public DataStore initialize(Map<String, Object> dsInfos) {
Long clusterId = (Long) dsInfos.get("clusterId");
Long podId = (Long) dsInfos.get("podId");
Long zoneId = (Long) dsInfos.get("zoneId");
String url = (String) dsInfos.get("url");
String providerName = (String) dsInfos.get("providerName");
if (clusterId != null && podId == null) {
throw new InvalidParameterValueException("Cluster id requires pod id");
}
PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters();
URI uri = null;
try {
uri = new URI(UriUtils.encodeURIComponent(url));
if (uri.getScheme() == null) {
throw new InvalidParameterValueException("scheme is null " + url + ", add nfs:// (or cifs://) as a prefix");
} else if (uri.getScheme().equalsIgnoreCase("nfs")) {
String uriHost = uri.getHost();
String uriPath = uri.getPath();
if (uriHost == null || uriPath == null || uriHost.trim().isEmpty() || uriPath.trim().isEmpty()) {
throw new InvalidParameterValueException("host or path is null, should be nfs://hostname/path");
}
} else if (uri.getScheme().equalsIgnoreCase("cifs")) {
// Don't validate against a URI encoded URI.
URI cifsUri = new URI(url);
String warnMsg = UriUtils.getCifsUriParametersProblems(cifsUri);
if (warnMsg != null) {
throw new InvalidParameterValueException(warnMsg);
}
} else if (uri.getScheme().equalsIgnoreCase("sharedMountPoint")) {
String uriPath = uri.getPath();
if (uriPath == null) {
throw new InvalidParameterValueException("host or path is null, should be sharedmountpoint://localhost/path");
}
} else if (uri.getScheme().equalsIgnoreCase("rbd")) {
String uriPath = uri.getPath();
if (uriPath == null) {
throw new InvalidParameterValueException("host or path is null, should be rbd://hostname/pool");
}
} else if (uri.getScheme().equalsIgnoreCase("gluster")) {
String uriHost = uri.getHost();
String uriPath = uri.getPath();
if (uriHost == null || uriPath == null || uriHost.trim().isEmpty() || uriPath.trim().isEmpty()) {
throw new InvalidParameterValueException("host or path is null, should be gluster://hostname/volume");
}
}
} catch (URISyntaxException e) {
throw new InvalidParameterValueException(url + " is not a valid uri");
}
String tags = (String) dsInfos.get("tags");
Map<String, String> details = (Map<String, String>) dsInfos.get("details");
parameters.setTags(tags);
parameters.setDetails(details);
String scheme = uri.getScheme();
String storageHost = uri.getHost();
String hostPath = null;
try {
hostPath = URLDecoder.decode(uri.getPath(), "UTF-8");
} catch (UnsupportedEncodingException e) {
s_logger.error("[ignored] we are on a platform not supporting \"UTF-8\"!?!", e);
}
if (hostPath == null) {
// if decoding fails, use getPath() anyway
hostPath = uri.getPath();
}
Object localStorage = dsInfos.get("localStorage");
if (localStorage != null) {
hostPath = hostPath.replaceFirst("/", "");
hostPath = hostPath.replace("+", " ");
}
String userInfo = uri.getUserInfo();
int port = uri.getPort();
if (s_logger.isDebugEnabled()) {
s_logger.debug("createPool Params @ scheme - " + scheme + " storageHost - " + storageHost + " hostPath - " + hostPath + " port - " + port);
}
if (scheme.equalsIgnoreCase("nfs")) {
if (port == -1) {
port = 2049;
}
parameters.setType(StoragePoolType.NetworkFilesystem);
parameters.setHost(storageHost);
parameters.setPort(port);
parameters.setPath(hostPath);
} else if (scheme.equalsIgnoreCase("cifs")) {
if (port == -1) {
port = 445;
}
parameters.setType(StoragePoolType.SMB);
parameters.setHost(storageHost);
parameters.setPort(port);
parameters.setPath(hostPath);
} else if (scheme.equalsIgnoreCase("file")) {
if (port == -1) {
port = 0;
}
parameters.setType(StoragePoolType.Filesystem);
parameters.setHost("localhost");
parameters.setPort(0);
parameters.setPath(hostPath);
} else if (scheme.equalsIgnoreCase("sharedMountPoint")) {
parameters.setType(StoragePoolType.SharedMountPoint);
parameters.setHost(storageHost);
parameters.setPort(0);
parameters.setPath(hostPath);
} else if (scheme.equalsIgnoreCase("clvm")) {
parameters.setType(StoragePoolType.CLVM);
parameters.setHost(storageHost);
parameters.setPort(0);
parameters.setPath(hostPath.replaceFirst("/", ""));
} else if (scheme.equalsIgnoreCase("rbd")) {
if (port == -1) {
port = 6789;
}
parameters.setType(StoragePoolType.RBD);
parameters.setHost(storageHost);
parameters.setPort(port);
parameters.setPath(hostPath.replaceFirst("/", ""));
parameters.setUserInfo(userInfo);
} else if (scheme.equalsIgnoreCase("PreSetup")) {
parameters.setType(StoragePoolType.PreSetup);
parameters.setHost(storageHost);
parameters.setPort(0);
parameters.setPath(hostPath);
} else if (scheme.equalsIgnoreCase("iscsi")) {
String[] tokens = hostPath.split("/");
int lun = NumbersUtil.parseInt(tokens[tokens.length - 1], -1);
if (port == -1) {
port = 3260;
}
if (lun != -1) {
if (clusterId == null) {
throw new IllegalArgumentException("IscsiLUN need to have clusters specified");
}
parameters.setType(StoragePoolType.IscsiLUN);
parameters.setHost(storageHost);
parameters.setPort(port);
parameters.setPath(hostPath);
} else {
throw new IllegalArgumentException("iSCSI needs to have LUN number");
}
} else if (scheme.equalsIgnoreCase("iso")) {
if (port == -1) {
port = 2049;
}
parameters.setType(StoragePoolType.ISO);
parameters.setHost(storageHost);
parameters.setPort(port);
parameters.setPath(hostPath);
} else if (scheme.equalsIgnoreCase("vmfs")) {
parameters.setType(StoragePoolType.VMFS);
parameters.setHost("VMFS datastore: " + hostPath);
parameters.setPort(0);
parameters.setPath(hostPath);
} else if (scheme.equalsIgnoreCase("ocfs2")) {
port = 7777;
parameters.setType(StoragePoolType.OCFS2);
parameters.setHost("clustered");
parameters.setPort(port);
parameters.setPath(hostPath);
} else if (scheme.equalsIgnoreCase("gluster")) {
if (port == -1) {
port = 24007;
}
parameters.setType(StoragePoolType.Gluster);
parameters.setHost(storageHost);
parameters.setPort(port);
parameters.setPath(hostPath);
} else {
StoragePoolType type = Enum.valueOf(StoragePoolType.class, scheme);
if (type != null) {
parameters.setType(type);
parameters.setHost(storageHost);
parameters.setPort(0);
parameters.setPath(hostPath);
} else {
s_logger.warn("Unable to figure out the scheme for URI: " + uri);
throw new IllegalArgumentException("Unable to figure out the scheme for URI: " + uri);
}
}
if (localStorage == null) {
List<StoragePoolVO> pools = primaryDataStoreDao.listPoolByHostPath(storageHost, hostPath);
if (!pools.isEmpty() && !scheme.equalsIgnoreCase("sharedmountpoint")) {
Long oldPodId = pools.get(0).getPodId();
throw new CloudRuntimeException("Storage pool " + uri + " already in use by another pod (id=" + oldPodId + ")");
}
}
Object existingUuid = dsInfos.get("uuid");
String uuid = null;
if (existingUuid != null) {
uuid = (String) existingUuid;
} else if (scheme.equalsIgnoreCase("sharedmountpoint") || scheme.equalsIgnoreCase("clvm")) {
uuid = UUID.randomUUID().toString();
} else if (scheme.equalsIgnoreCase("PreSetup")) {
uuid = hostPath.replace("/", "");
} else {
uuid = UUID.nameUUIDFromBytes((storageHost + hostPath).getBytes()).toString();
}
List<StoragePoolVO> spHandles = primaryDataStoreDao.findIfDuplicatePoolsExistByUUID(uuid);
if ((spHandles != null) && (spHandles.size() > 0)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Another active pool with the same uuid already exists");
}
throw new CloudRuntimeException("Another active pool with the same uuid already exists");
}
String poolName = (String) dsInfos.get("name");
parameters.setUuid(uuid);
parameters.setZoneId(zoneId);
parameters.setPodId(podId);
parameters.setName(poolName);
parameters.setClusterId(clusterId);
parameters.setProviderName(providerName);
return dataStoreHelper.createPrimaryDataStore(parameters);
}
Aggregations