use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class DatabaseConfig method saveStoragePool.
@DB
public void saveStoragePool() {
String name = _currentObjectParams.get("name");
long id = Long.parseLong(_currentObjectParams.get("id"));
long dataCenterId = Long.parseLong(_currentObjectParams.get("zoneId"));
long podId = Long.parseLong(_currentObjectParams.get("podId"));
long clusterId = Long.parseLong(_currentObjectParams.get("clusterId"));
String hostAddress = _currentObjectParams.get("hostAddress");
String hostPath = _currentObjectParams.get("hostPath");
String storageType = _currentObjectParams.get("storageType");
String uuid = UUID.nameUUIDFromBytes(new String(hostAddress + hostPath).getBytes()).toString();
String insertSql1 = "INSERT INTO `storage_pool` (`id`, `name`, `uuid` , `pool_type` , `port`, `data_center_id` ,`available_bytes` , `capacity_bytes` ,`host_address`, `path`, `created`, `pod_id`,`status` , `cluster_id`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
// String insertSql2 = "INSERT INTO `netfs_storage_pool` VALUES (?,?,?)";
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql1);
stmt.setLong(1, id);
stmt.setString(2, name);
stmt.setString(3, uuid);
if (storageType == null) {
stmt.setString(4, "NetworkFileSystem");
} else {
stmt.setString(4, storageType);
}
stmt.setLong(5, 111);
stmt.setLong(6, dataCenterId);
stmt.setLong(7, 0);
stmt.setLong(8, 0);
stmt.setString(9, hostAddress);
stmt.setString(10, hostPath);
stmt.setDate(11, new Date(new java.util.Date().getTime()));
stmt.setLong(12, podId);
stmt.setString(13, Status.Up.toString());
stmt.setLong(14, clusterId);
stmt.executeUpdate();
} catch (SQLException ex) {
System.out.println("Error creating storage pool: " + ex.getMessage());
s_logger.error("error creating storage pool ", ex);
return;
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class DatabaseConfig method getDatabaseValueString.
public static String getDatabaseValueString(String selectSql, String name, String errorMsg) {
TransactionLegacy txn = TransactionLegacy.open("getDatabaseValueString");
PreparedStatement stmt = null;
try {
stmt = txn.prepareAutoCloseStatement(selectSql);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
String value = rs.getString(name);
return value;
} else {
return null;
}
} catch (SQLException e) {
System.out.println("Exception: " + e.getMessage());
printError(errorMsg);
} finally {
txn.close();
}
return null;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class DatabaseConfig method saveRootDomain.
@DB
protected void saveRootDomain() {
String insertSql = "insert into `cloud`.`domain` (id, name, parent, owner, path, level) values (1, 'ROOT', NULL, 2, '/', 0)";
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
stmt.executeUpdate();
} catch (SQLException ex) {
s_logger.error("error creating ROOT domain", ex);
}
/*
String updateSql = "update account set domain_id = 1 where id = 2";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareStatement(updateSql);
stmt.executeUpdate();
} catch (SQLException ex) {
s_logger.error("error updating admin user", ex);
} finally {
txn.close();
}
updateSql = "update account set domain_id = 1 where id = 1";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareStatement(updateSql);
stmt.executeUpdate();
} catch (SQLException ex) {
s_logger.error("error updating system user", ex);
} finally {
txn.close();
}
*/
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class IPRangeConfig method deleteIPRange.
@DB
protected Vector<String> deleteIPRange(String type, long podId, long zoneId, long vlanDbId, String startIP, String endIP) {
long startIPLong = NetUtils.ip2Long(startIP);
long endIPLong = startIPLong;
if (endIP != null) {
endIPLong = NetUtils.ip2Long(endIP);
}
TransactionLegacy txn = TransactionLegacy.currentTxn();
Vector<String> problemIPs = null;
if (type.equals("public")) {
problemIPs = deletePublicIPRange(txn, startIPLong, endIPLong, vlanDbId);
} else if (type.equals("private")) {
problemIPs = deletePrivateIPRange(txn, startIPLong, endIPLong, podId, zoneId);
}
return problemIPs;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class PodZoneConfig method savePhysicalNetwork.
@DB
public void savePhysicalNetwork(boolean printOutput, long id, long dcId, int vnetStart, int vnetEnd) {
if (printOutput)
System.out.println("Saving physical network, please wait...");
String columns = null;
String values = null;
columns = "(id ";
values = "('" + id + "'";
columns += ", name ";
values += ",'physical network'";
columns += ", data_center_id ";
values += ",'" + dcId + "'";
//save vnet information
columns += ", vnet";
values += ",'" + vnetStart + "-" + vnetEnd + "'";
columns += ", state";
values += ", 'Enabled'";
columns += ", uuid";
values += ", UUID()";
columns += ")";
values += ")";
String sql = "INSERT INTO `cloud`.`physical_network` " + columns + " VALUES " + values;
DatabaseConfig.saveSQL(sql, "Failed to save physical network due to exception. Please contact Cloud Support.");
// Hardcode the vnet range to be the full range
int begin = 0x64;
int end = 64000;
// If vnet arguments were passed in, use them
if (vnetStart != -1 && vnetEnd != -1) {
begin = vnetStart;
end = vnetEnd;
}
String insertVnet = "INSERT INTO `cloud`.`op_dc_vnet_alloc` (vnet, data_center_id, physical_network_id) VALUES ( ?, ?, ?)";
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertVnet);
for (int i = begin; i <= end; i++) {
stmt.setString(1, Integer.toString(i));
stmt.setLong(2, dcId);
stmt.setLong(3, id);
stmt.addBatch();
}
stmt.executeBatch();
} catch (SQLException ex) {
printError("Error creating vnet for the physical network. Please contact Cloud Support.");
}
//add default traffic types
//get default Xen network labels
String defaultXenPrivateNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Management);
String defaultXenPublicNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Public);
String defaultXenStorageNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Storage);
String defaultXenGuestNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Guest);
String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` " + "(physical_network_id, traffic_type, xenserver_network_label) VALUES ( ?, ?, ?)";
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertTraficType);
for (TrafficType traffic : TrafficType.values()) {
if (traffic.equals(TrafficType.Control) || traffic.equals(TrafficType.Vpn) || traffic.equals(TrafficType.None)) {
continue;
}
stmt.setLong(1, id);
stmt.setString(2, traffic.toString());
if (traffic.equals(TrafficType.Public)) {
stmt.setString(3, defaultXenPublicNetworkLabel);
} else if (traffic.equals(TrafficType.Management)) {
stmt.setString(3, defaultXenPrivateNetworkLabel);
} else if (traffic.equals(TrafficType.Storage)) {
stmt.setString(3, defaultXenStorageNetworkLabel);
} else if (traffic.equals(TrafficType.Guest)) {
stmt.setString(3, defaultXenGuestNetworkLabel);
}
stmt.addBatch();
}
stmt.executeBatch();
} catch (SQLException ex) {
printError("Error adding default traffic types for the physical network. Please contact Cloud Support.");
}
if (printOutput)
System.out.println("Successfully saved physical network.");
}
Aggregations