use of org.apache.cloudstack.storage.datastore.util.ElastistorUtil.Tsm in project cloudstack by apache.
the class ElastistorPrimaryDataStoreLifeCycle method initialize.
@Override
public DataStore initialize(Map<String, Object> dsInfos) {
String url = (String) dsInfos.get("url");
Long zoneId = (Long) dsInfos.get("zoneId");
Long podId = (Long) dsInfos.get("podId");
Long clusterId = (Long) dsInfos.get("clusterId");
String storagePoolName = (String) dsInfos.get("name");
String providerName = (String) dsInfos.get("providerName");
Long capacityBytes = (Long) dsInfos.get("capacityBytes");
Long capacityIops = (Long) dsInfos.get("capacityIops");
String tags = (String) dsInfos.get("tags");
boolean managed = (Boolean) dsInfos.get("managed");
Map<String, String> details = (Map<String, String>) dsInfos.get("details");
String domainName = details.get("domainname");
String storageIp;
int storagePort = 0;
StoragePoolType storagetype = null;
String accesspath = null;
String protocoltype = null;
String mountpoint = null;
if (!managed) {
storageIp = getStorageIp(url);
storagePort = getDefaultStoragePort(url);
storagetype = getStorageType(url);
accesspath = getAccessPath(url);
protocoltype = getProtocolType(url);
String[] mp = accesspath.split("/");
mountpoint = mp[1];
} else if (details.get("hypervisortype") == "KVM") {
storageIp = url;
storagePort = 3260;
storagetype = StoragePoolType.Iscsi;
accesspath = storageIp + ":/" + storagePoolName;
} else {
storageIp = url;
storagePort = 2049;
storagetype = StoragePoolType.NetworkFilesystem;
accesspath = storageIp + ":/" + storagePoolName;
}
/**
* if the elastistor params which are required for plugin configuration
* are not injected through spring-storage-volume-cloudbyte-context.xml,
* it can be set from details map.
*/
if (details.get("esaccountid") != null)
ElastistorUtil.setElastistorAccountId(details.get("esaccountid"));
if (details.get("esdefaultgateway") != null)
ElastistorUtil.setElastistorGateway(details.get("esdefaultgateway"));
if (details.get("estntinterface") != null)
ElastistorUtil.setElastistorInterface(details.get("estntinterface"));
if (details.get("espoolid") != null)
ElastistorUtil.setElastistorPoolId(details.get("espoolid"));
if (details.get("essubnet") != null)
ElastistorUtil.setElastistorSubnet(details.get("essubnet"));
s_logger.info("Elastistor details was set successfully.");
if (capacityBytes == null || capacityBytes <= 0) {
throw new IllegalArgumentException("'capacityBytes' must be present and greater than 0.");
}
if (capacityIops == null || capacityIops <= 0) {
throw new IllegalArgumentException("'capacityIops' must be present and greater than 0.");
}
if (domainName == null) {
domainName = "ROOT";
s_logger.debug("setting the domain to ROOT");
}
// elastistor does not allow same name and ip pools.
List<StoragePoolVO> storagePoolVO = _storagePoolDao.listAll();
for (StoragePoolVO poolVO : storagePoolVO) {
if (storagePoolName.equals(poolVO.getName())) {
throw new IllegalArgumentException("Storage pool with this name already exists in elastistor, please specify a unique name. [name:" + storagePoolName + "]");
}
if (storageIp.equals(poolVO.getHostAddress())) {
throw new IllegalArgumentException("Storage pool with this ip already exists in elastistor, please specify a unique ip. [ip:" + storageIp + "]");
}
}
PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters();
parameters.setHost(storageIp);
parameters.setPort(storagePort);
parameters.setPath(accesspath);
parameters.setType(storagetype);
parameters.setZoneId(zoneId);
parameters.setPodId(podId);
parameters.setName(storagePoolName);
parameters.setProviderName(providerName);
parameters.setManaged(managed);
parameters.setCapacityBytes(capacityBytes);
parameters.setUsedBytes(0);
parameters.setCapacityIops(capacityIops);
parameters.setHypervisorType(HypervisorType.Any);
parameters.setTags(tags);
parameters.setDetails(details);
parameters.setClusterId(clusterId);
Tsm tsm = null;
if (managed) {
// creates the TSM in elastistor
tsm = createElastistorTSM(storagePoolName, storageIp, capacityBytes, capacityIops, domainName);
} else {
// creates the TSM & Volume in elastistor
tsm = createElastistorTSM(storagePoolName, storageIp, capacityBytes, capacityIops, domainName);
parameters = createElastistorVolume(parameters, tsm, storagePoolName, capacityBytes, capacityIops, protocoltype, mountpoint);
}
// setting tsm's uuid as storagepool's uuid
parameters.setUuid(tsm.getUuid());
return _dataStoreHelper.createPrimaryDataStore(parameters);
}
use of org.apache.cloudstack.storage.datastore.util.ElastistorUtil.Tsm in project cloudstack by apache.
the class ElastistorPrimaryDataStoreLifeCycle method createElastistorTSM.
private Tsm createElastistorTSM(String storagePoolName, String storageIp, Long capacityBytes, Long capacityIops, String domainName) {
s_logger.info("Creation of elastistor TSM started.");
Tsm tsm;
String elastistorAccountId;
try {
// to create a tsm , account id is required, so getting the account id for the given cloudstack domain
elastistorAccountId = ElastistorUtil.getElastistorAccountId(domainName);
// create the tsm for the given account id
tsm = ElastistorUtil.createElastistorTsm(storagePoolName, storageIp, capacityBytes, capacityIops, elastistorAccountId);
} catch (Throwable e) {
s_logger.error("Failed to create TSM in elastistor.", e);
throw new CloudRuntimeException("Failed to create TSM in elastistor. " + e.getMessage());
}
s_logger.info("Creation of elastistor TSM completed successfully.");
return tsm;
}
Aggregations