private void unregisterDataSource(String dsName) { CarbonDataSource cds = this.getDataSource(dsName); if (cds == null) { return; } if (log.isDebugEnabled()) { log.debug("Unregistering data source: " + dsName); } this.unregisterJNDI(cds.getDSMInfo()); this.dataSources.remove(dsName); }
/** * Unregisters and deletes the data source from the repository. * * @param dsName The data source name */ public void deleteDataSource(String dsName) throws DataSourceException { if (log.isDebugEnabled()) { log.debug("Deleting data source: " + dsName); } CarbonDataSource cds = this.getDataSource(dsName); if (cds == null) { throw new DataSourceException("Data source does not exist: " + dsName); } if (cds.getDSMInfo().isSystem()) { throw new DataSourceException("System data sources cannot be deleted: " + dsName); } this.removePersistedDataSource(dsName); this.unregisterDataSource(dsName); this.notifyClusterDSChange(dsName); }
private synchronized void registerDataSource(DataSourceMetaInfo dsmInfo) throws DataSourceException { /* if a data source is already registered with the given name, unregister it first */ CarbonDataSource currentCDS = this.getDataSource(dsmInfo.getName()); if (currentCDS != null) { /* if the data source is a system data source, throw exception */ if (dsmInfo.isSystem()) { throw new DataSourceException( "System datasource " + dsmInfo.getName() + "can not be updated."); } this.unregisterDataSource(currentCDS.getDSMInfo().getName()); } if (log.isDebugEnabled()) { log.debug("Registering data source: " + dsmInfo.getName()); } Object dsObject = null; boolean isDataSourceFactoryReference = false; DataSourceStatus dsStatus; try { JNDIConfig jndiConfig = dsmInfo.getJndiConfig(); if (jndiConfig != null) { isDataSourceFactoryReference = jndiConfig.isUseDataSourceFactory(); } dsObject = this.createDataSourceObject(dsmInfo, isDataSourceFactoryReference); this.registerJNDI(dsmInfo, dsObject); dsStatus = new DataSourceStatus(DataSourceStatusModes.ACTIVE, null); } catch (Exception e) { String msg = "Error in registering data source: " + dsmInfo.getName() + " - " + e.getMessage(); log.error(msg, e); dsStatus = new DataSourceStatus(DataSourceStatusModes.ERROR, msg); } /* Creating DataSource object , if dsObject is a Reference */ if (isDataSourceFactoryReference) { dsObject = this.createDataSourceObject(dsmInfo, false); } CarbonDataSource cds = new CarbonDataSource(dsmInfo, dsStatus, dsObject); this.dataSources.put(cds.getDSMInfo().getName(), cds); }
private synchronized void updateDataSource(String dsName, boolean unregister) throws DataSourceException { String dsmPath = DataSourceConstants.DATASOURCES_REPOSITORY_BASE_PATH + "/" + dsName; try { DataSourceMetaInfo dsmInfo = this.getDataSourceMetaInfoFromRegistryPath(dsmPath); CarbonDataSource currentCDS = this.getDataSource(dsName); DataSourceMetaInfo currentDsmInfo = null; if (currentCDS != null) { currentDsmInfo = currentCDS.getDSMInfo(); } if (unregister) { this.unregisterDataSource(dsName); } else { if (DataSourceUtils.nullAllowEquals(dsmInfo, currentDsmInfo)) { if (log.isDebugEnabled()) { log.debug("No update change for data source: " + dsName); } return; } if (dsmInfo != null) { this.registerDataSource(dsmInfo); } else { this.unregisterDataSource(dsName); } } } catch (Exception e) { throw new DataSourceException( "Error in updating data source '" + dsName + "' from registry [remove:" + unregister + "]: " + e.getMessage(), e); } }