use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.
the class StagedResource method getInputStream.
public synchronized InputStream getInputStream() {
Thread thread = Thread.currentThread();
InputStream reader = inputStreams != null ? inputStreams.get(thread) : null;
if (reader == null) {
if (file != null && file.exists()) {
try {
reader = new BufferedInputStream(new FileInputStream(file));
createInputStreamsMap();
inputStreams.put(thread, reader);
} catch (IOException ex) {
throw new IoException(ex);
}
} else {
throw new IllegalStateException("There is no content to read. " + file.getAbsolutePath() + " was not found.");
}
}
return reader;
}
use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.
the class AbstractTest method getWebServer.
protected SymmetricWebServer getWebServer(String name) {
try {
if (!webServers.containsKey(name)) {
EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(new URL[] { getResource(DbTestUtils.DB_TEST_PROPERTIES) }, "test." + name, new String[] { name });
properties.putAll(getProperties(name));
File rootDir = new File("target/" + name);
FileUtils.deleteDirectory(rootDir);
rootDir.mkdirs();
File engineDir = new File(rootDir, "engines");
engineDir.mkdirs();
File rootPropertiesFile = new File(engineDir, "root.properties");
FileOutputStream fos = new FileOutputStream(rootPropertiesFile);
properties.store(fos, "unit tests");
fos.close();
System.setProperty(SystemConstants.SYSPROP_WAIT_FOR_DATABASE, "false");
System.setProperty(SystemConstants.SYSPROP_ENGINES_DIR, engineDir.getAbsolutePath());
System.setProperty(SystemConstants.SYSPROP_WEB_DIR, "src/main/deploy/web");
ISymmetricEngine engine = null;
int tries = 2;
do {
/**
* Firebird is flaky. Trying to work around it.
*/
try {
engine = new ClientSymmetricEngine(properties);
} catch (Exception ex) {
log.warn("Failed to create engine on the first try. Trying again. The root cause of the first failure was: ", ex);
tries--;
AppUtils.sleep(30000);
}
} while (tries > 0 && engine == null);
IDatabasePlatform platform = engine.getDatabasePlatform();
engine.getStagingManager().clean(0);
engine.uninstall();
Database database = platform.getDdlReader().readTables(platform.getDefaultCatalog(), platform.getDefaultSchema(), new String[] { "TABLE" });
platform.dropDatabase(database, true);
Table[] tables = getTables(name);
if (tables != null) {
platform.alterCaseToMatchDatabaseDefaultCase(tables);
platform.createTables(false, true, tables);
}
engine.destroy();
SymmetricWebServer server = new SymmetricWebServer();
server.setJmxEnabled(false);
server.setHttpPort(port);
log.info("Starting " + name + " on port " + port);
server.setJoin(false);
server.start();
server.waitForEnginesToComeOnline(240000);
webServers.put(name, server);
port += 200;
}
return webServers.get(name);
} catch (IOException e) {
throw new IoException(e);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.
the class RestService method postRegisterNode.
@ApiOperation(value = "Register the specified node for the specified engine")
@RequestMapping(value = "/engine/{engine}/registernode", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final RegistrationInfo postRegisterNode(@PathVariable("engine") String engineName, @RequestParam(value = "externalId") String externalId, @RequestParam(value = "nodeGroupId") String nodeGroupId, @RequestParam(value = "databaseType") String databaseType, @RequestParam(value = "databaseVersion") String databaseVersion, @RequestParam(value = "hostName") String hostName) {
ISymmetricEngine engine = getSymmetricEngine(engineName);
IRegistrationService registrationService = engine.getRegistrationService();
INodeService nodeService = engine.getNodeService();
RegistrationInfo regInfo = new org.jumpmind.symmetric.web.rest.model.RegistrationInfo();
try {
org.jumpmind.symmetric.model.Node processedNode = registrationService.registerPullOnlyNode(externalId, nodeGroupId, databaseType, databaseVersion);
regInfo.setRegistered(processedNode.isSyncEnabled());
if (regInfo.isRegistered()) {
regInfo.setNodeId(processedNode.getNodeId());
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(processedNode.getNodeId());
regInfo.setNodePassword(nodeSecurity.getNodePassword());
org.jumpmind.symmetric.model.Node modelNode = nodeService.findIdentity();
regInfo.setSyncUrl(modelNode.getSyncUrl());
// do an initial heartbeat
Heartbeat heartbeat = new Heartbeat();
heartbeat.setNodeId(regInfo.getNodeId());
heartbeat.setHostName(hostName);
Date now = new Date();
heartbeat.setCreateTime(now);
heartbeat.setLastRestartTime(now);
heartbeat.setHeartbeatTime(now);
this.heartbeatImpl(engine, heartbeat);
}
// TODO: Catch a RegistrationRedirectException and redirect.
} catch (IOException e) {
throw new IoException(e);
}
return regInfo;
}
Aggregations