use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.
the class SystemApplicationDaoImpl method addApplicationKey.
@Override
public void addApplicationKey(String appName, String consumerKey) throws APIMgtDAOException {
final String query = "INSERT INTO AM_SYSTEM_APPS (NAME,CONSUMER_KEY,CREATED_TIME) VALUES (?,?,?)";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
connection.setAutoCommit(false);
try {
statement.setString(1, appName);
statement.setString(2, consumerKey);
statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now()), Calendar.getInstance(TimeZone.getTimeZone("UTC")));
log.debug("Executing query: {} ", query);
statement.execute();
connection.commit();
} catch (SQLException ex) {
connection.rollback();
throw new APIMgtDAOException("Couldn't Create System Application", ex);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMsg = "Error while creating database connection/prepared-statement";
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.
the class APIPublisherImpl method addAPIFromWSDLFile.
@Override
public String addAPIFromWSDLFile(API.APIBuilder apiBuilder, InputStream inputStream, boolean isHttpBinding) throws APIManagementException {
byte[] wsdlContent;
try {
wsdlContent = IOUtils.toByteArray(inputStream);
} catch (IOException e) {
throw new APIMgtWSDLException("Error while converting input stream to byte array", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
}
WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(processor.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
if (!processor.canProcess()) {
throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
String uuid = addAPI(apiBuilder);
if (log.isDebugEnabled()) {
log.debug("Successfully added the API. uuid: " + uuid);
}
getApiDAO().addOrUpdateWSDL(uuid, wsdlContent, getUsername());
if (log.isDebugEnabled()) {
log.debug("Successfully added the WSDL file to database. API uuid: " + uuid);
}
if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(processor.getWsdlInfo().getVersion())) {
log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
}
return uuid;
}
use of org.wso2.carbon.humantask.core.db.Database in project wso2-synapse by wso2.
the class DataSourceInformationSerializerTest method testSerializeDataSourceInformation.
/**
* Test serializing DataSourceInformation list
*/
public void testSerializeDataSourceInformation() {
List<DataSourceInformation> dataSourceInformationList = new ArrayList<>();
DataSourceInformation dataSourceInformation1 = new DataSourceInformation();
dataSourceInformation1.setDriver("org.h2.Driver");
dataSourceInformation1.setUrl("jdbc:h2:repository/database/test_db1");
dataSourceInformation1.setAlias("dataSource1");
SecretInformation secretInformation = new SecretInformation();
secretInformation.setUser("user1");
secretInformation.setAliasSecret("user1password");
dataSourceInformation1.setSecretInformation(secretInformation);
dataSourceInformationList.add(dataSourceInformation1);
DataSourceInformation dataSourceInformation2 = new DataSourceInformation();
dataSourceInformation2.setDriver("org.h2.Driver");
dataSourceInformation2.setUrl("jdbc:h2:repository/database/test_db2");
dataSourceInformation2.setAlias("dataSource2");
dataSourceInformationList.add(dataSourceInformation2);
DataSourceInformation dataSourceInformation3 = new DataSourceInformation();
dataSourceInformation3.setDriver("org.h2.Driver");
dataSourceInformation3.setUrl("jdbc:h2:repository/database/test_db3");
dataSourceInformation3.setAlias("dataSource3");
dataSourceInformationList.add(dataSourceInformation3);
Properties properties = DataSourceInformationListSerializer.serialize(dataSourceInformationList);
String dataSources = properties.getProperty("synapse.datasources");
assertTrue("'dataSource1' cannot be found in datasource list ", dataSources.contains("dataSource1"));
assertTrue("'dataSource2' cannot be found in datasource list ", dataSources.contains("dataSource2"));
assertTrue("'dataSource3' cannot be found in datasource list ", dataSources.contains("dataSource3"));
}
use of org.wso2.carbon.humantask.core.db.Database in project carbon-business-process by wso2.
the class BPELServerImpl method initDataSource.
/**
* Initialize the data source.
*
* @throws BPELEngineException If error occured while initializing datasource
*/
private void initDataSource() throws BPELEngineException {
db = new Database(odeConfigurationProperties);
db.setTransactionManager(transactionManager);
if (System.getProperty("setup") != null) {
BPELDatabaseCreator bpelDBCreator;
try {
bpelDBCreator = new BPELDatabaseCreator(db.<DataSource>lookupInJndi(odeConfigurationProperties.getDbDataSource()));
} catch (Exception e) {
String errMsg = "Error creating BPELDatabaseCreator";
log.error(errMsg, e);
throw new BPELEngineException(errMsg, e);
}
if (!bpelDBCreator.isDatabaseStructureCreated("SELECT * FROM ODE_SCHEMA_VERSION")) {
try {
// TODO rename following method
bpelDBCreator.createRegistryDatabase();
} catch (Exception e) {
String errMsg = "Error creating BPEL database";
log.error(errMsg, e);
throw new BPELEngineException(errMsg, e);
}
} else {
if (log.isDebugEnabled()) {
log.debug("BPEL database already exists. Using the old database.");
}
}
}
// In carbon, embedded H2 database for ODE is located at CARBON_HOME/repository/database
String dbRoot = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "database";
File dbRootDir = new File(dbRoot);
if (dbRootDir.exists() && dbRootDir.isDirectory()) {
db.setWorkRoot(dbRootDir);
} else {
db.setWorkRoot(null);
}
try {
db.start();
} catch (Exception e) {
String errMsg = "Error starting database connections, check the database configuration!";
log.error(errMsg, e);
throw new BPELEngineException(errMsg, e);
}
}
use of org.wso2.carbon.humantask.core.db.Database in project carbon-business-process by wso2.
the class SimpleScheduler method doLoadImmediate.
boolean doLoadImmediate() {
if (log.isDebugEnabled()) {
log.debug("LOAD IMMEDIATE started");
}
// don't load anything if we're already half-full; we've got plenty to do already
if (outstandingJobs.size() > todoLimit / 2) {
return true;
}
List<Job> jobs = new ArrayList<Job>();
try {
// don't load more than we can chew
int tps = 100;
final int batch = Math.min((int) (immediateInterval * tps / 1000), todoLimit - outstandingJobs.size());
// jobs might have been enqueued by #addTodoList meanwhile
if (batch <= 0) {
if (log.isDebugEnabled()) {
log.debug("Max capacity reached: " + outstandingJobs.size() + " jobs dispacthed i.e. queued or being executed");
}
return true;
}
if (log.isDebugEnabled()) {
log.debug("Started loading " + batch + " jobs from db");
}
// jobs = _db.dequeueImmediate(_nodeId, System.currentTimeMillis() + _immediateInterval, batch);
List<HumanTaskJobDAO> htJobs = execTransaction(new Callable<List<HumanTaskJobDAO>>() {
public List<HumanTaskJobDAO> call() throws Exception {
return getConnection().dequeueImmediate(nodeId, System.currentTimeMillis() + immediateInterval, batch);
}
});
for (HumanTaskJobDAO htJob : htJobs) {
jobs.add(new Job(htJob));
}
if (log.isDebugEnabled()) {
log.debug("loaded " + jobs.size() + " jobs from db");
}
long warningDelay = 0;
long delayedTime = System.currentTimeMillis() - warningDelay;
int delayedCount = 0;
boolean runningLate;
AbsoluteTimeDateFormat f = new AbsoluteTimeDateFormat();
for (Job j : jobs) {
// jobs might have been enqueued by #addTodoList meanwhile
if (outstandingJobs.size() >= todoLimit) {
if (log.isDebugEnabled()) {
log.debug("Max capacity reached: " + outstandingJobs.size() + " jobs dispacthed i.e. queued or being executed");
}
break;
}
runningLate = j.schedDate <= delayedTime;
if (runningLate) {
// TODO run the job here
delayedCount++;
}
if (log.isDebugEnabled()) {
log.debug("todo.enqueue job from db: " + j.getJobID() + " for " + j.schedDate + "(" + f.format(j.schedDate) + ") " + (runningLate ? " delayed=true" : ""));
}
enqueue(j);
}
if (delayedCount > 0) {
log.warn("Dispatching jobs with more than " + (warningDelay / 60000) + " minutes delay. Either the server was down for some time or the job " + "load is greater than available capacity");
}
// clear only if the batch succeeded
processedSinceLastLoadTask.clear();
return true;
} catch (Exception ex) {
log.error("Error loading immediate jobs from database.", ex);
return false;
} finally {
if (log.isDebugEnabled()) {
log.debug("LOAD IMMEDIATE complete");
}
}
}
Aggregations