use of org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource in project airavata by apache.
the class ExperimentCatalogInitUtil method initializeDB.
public static void initializeDB() {
System.setProperty("registry.initialize.state", "0");
try {
jdbcDriver = ServerSettings.getSetting(REGISTRY_JDBC_DRIVER);
jdbcURl = ServerSettings.getSetting(REGISTRY_JDBC_URL);
jdbcUser = ServerSettings.getSetting(REGISTRY_JDBC_USER);
jdbcPassword = ServerSettings.getSetting(REGISTRY_JDBC_PASSWORD);
jdbcURl = jdbcURl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
} catch (ApplicationSettingsException e) {
logger.error("Unable to read airavata server properties", e.getMessage());
}
if (getDBType(jdbcURl).equals("derby") && isDerbyStartEnabled()) {
startDerbyInServerMode();
}
db = new JdbcStorage(10, 50, jdbcURl, jdbcDriver, true);
Connection conn = null;
try {
conn = db.connect();
if (!DatabaseCreator.isDatabaseStructureCreated(CONFIGURATION_TABLE, conn)) {
DatabaseCreator.createRegistryDatabase("database_scripts/expcatalog", conn);
logger.info("New Database created for Experiment Catalog !!!");
} else {
logger.info("Database already created for Experiment Catalog !!!");
}
try {
GatewayResource gateway;
if (!ExpCatResourceUtils.isGatewayExist(ServerSettings.getDefaultUserGateway())) {
gateway = (GatewayResource) ExpCatResourceUtils.createGateway(ServerSettings.getDefaultUserGateway());
gateway.setGatewayApprovalStatus(GatewayApprovalStatus.APPROVED.toString());
gateway.save();
} else {
gateway = (GatewayResource) ExpCatResourceUtils.getGateway(ServerSettings.getDefaultUserGateway());
}
UserResource user;
if (!ExpCatResourceUtils.isUserExist(ServerSettings.getDefaultUser(), ServerSettings.getDefaultUserGateway())) {
user = ExpCatResourceUtils.createUser(ServerSettings.getDefaultUser(), ServerSettings.getDefaultUserPassword(), ServerSettings.getDefaultUserGateway());
user.save();
} else {
user = (UserResource) ExpCatResourceUtils.getUser(ServerSettings.getDefaultUser(), ServerSettings.getDefaultUserGateway());
}
WorkerResource workerResource;
if (!gateway.isExists(ResourceType.GATEWAY_WORKER, ServerSettings.getDefaultUserGateway())) {
workerResource = (WorkerResource) gateway.create(ResourceType.GATEWAY_WORKER);
workerResource.setUser(user.getUserName());
workerResource.save();
} else {
workerResource = (WorkerResource) gateway.get(ResourceType.GATEWAY_WORKER, ServerSettings.getDefaultUser());
}
ProjectResource projectResource;
if (!workerResource.isExists(ResourceType.PROJECT, DEFAULT_PROJECT_NAME)) {
projectResource = workerResource.createProject(DEFAULT_PROJECT_NAME);
projectResource.setName(DEFAULT_PROJECT_NAME);
projectResource.setGatewayId(gateway.getGatewayId());
projectResource.save();
}
} catch (ApplicationSettingsException e) {
logger.error("Unable to read airavata-server properties...", e.getMessage());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RuntimeException("Database failure", e);
} finally {
db.closeConnection(conn);
try {
if (conn != null) {
if (!conn.getAutoCommit()) {
conn.commit();
}
conn.close();
}
} catch (SQLException e) {
logger.error("Error while closing database connection...", e.getMessage(), e);
}
}
System.setProperty("registry.initialize.state", "1");
}
Aggregations