Search in sources :

Example 6 with DatabaseInitException

use of org.bimserver.database.berkeley.DatabaseInitException in project BIMserver by opensourceBIM.

the class LocalDevBimServerStarter method start.

public void start(int id, String address, String name, int port, int pbport, Path[] pluginDirectories, Path home) {
    BimServerConfig config = new BimServerConfig();
    if (home != null) {
        config.setHomeDir(home);
    } else {
        config.setHomeDir(Paths.get("tmptestdata/home" + (id == -1 ? "" : id)));
    }
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    config.setStartEmbeddedWebServer(true);
    config.setClassPath(System.getProperty("java.class.path"));
    config.setLocalDev(true);
    config.setEnvironment(Environment.LOCAL_DEV);
    config.setPort(port);
    config.setStartCommandLine(true);
    config.setDevelopmentBaseDir(Paths.get("../BimServer"));
    try {
        fixLogging(config);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    bimServer = new BimServer(config);
    bimServer.getVersionChecker().getLocalVersion().setDate(new Date());
    bimServer.setEmbeddedWebServer(new EmbeddedWebServer(bimServer, config.getDevelopmentBaseDir(), config.isLocalDev()));
    Logger LOGGER = LoggerFactory.getLogger(LocalDevBimServerStarter.class);
    try {
        bimServer.start();
        if (bimServer.getServerInfo().getServerState() == ServerState.MIGRATION_REQUIRED) {
            bimServer.getServerInfoManager().registerStateChangeListener(new StateChangeListener() {

                @Override
                public void stateChanged(ServerState oldState, ServerState newState) {
                    if (oldState == ServerState.MIGRATION_REQUIRED && newState == ServerState.RUNNING) {
                        try {
                            LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirectories);
                        } catch (PluginException e) {
                            LOGGER.error("", e);
                        }
                    }
                }
            });
        } else if (bimServer.getServerInfo().getServerState() == ServerState.RUNNING || bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirectories);
            try {
                AdminInterface adminInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(AdminInterface.class);
                adminInterface.setup("http://localhost:" + port, name, "My Description", "http://localhost:" + port + "/img/bimserver.png", "Administrator", "admin@bimserver.org", "admin");
                SettingsInterface settingsInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(SettingsInterface.class);
                settingsInterface.setCacheOutputFiles(false);
                settingsInterface.setPluginStrictVersionChecking(false);
            } catch (Exception e) {
            // Ignore
            }
            bimServer.activateServices();
        } else {
            LOGGER.error("BIMserver did not startup correctly");
        }
    } catch (PluginException e) {
        LOGGER.error("", e);
    } catch (ServiceException e) {
        LOGGER.error("", e);
    } catch (DatabaseInitException e) {
        LOGGER.error("", e);
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } catch (DatabaseRestartRequiredException e) {
        LOGGER.error("", e);
    }
}
Also used : ServerState(org.bimserver.models.store.ServerState) PluginException(org.bimserver.shared.exceptions.PluginException) IOException(java.io.IOException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) Logger(org.slf4j.Logger) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) Date(java.util.Date) PluginException(org.bimserver.shared.exceptions.PluginException) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException)

Example 7 with DatabaseInitException

use of org.bimserver.database.berkeley.DatabaseInitException in project BIMserver by opensourceBIM.

the class TestSimultaniousDownloadWithCaching method start.

private void start() {
    BimServerConfig config = new BimServerConfig();
    Path homeDir = Paths.get("home");
    try {
        if (Files.isDirectory(homeDir)) {
            PathUtils.removeDirectoryWithContent(homeDir);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    config.setClassPath(System.getProperty("java.class.path"));
    config.setHomeDir(homeDir);
    config.setPort(8080);
    config.setStartEmbeddedWebServer(true);
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    final BimServer bimServer = new BimServer(config);
    try {
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null);
        bimServer.start();
        if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null);
        }
    } catch (PluginException e2) {
        e2.printStackTrace();
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (DatabaseInitException e) {
        e.printStackTrace();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (DatabaseRestartRequiredException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    }
    try {
        final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
        ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class);
        SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class);
        final AuthInterface authInterface = serviceMap.get(AuthInterface.class);
        serviceInterface = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL).get(ServiceInterface.class);
        settingsInterface.setCacheOutputFiles(true);
        settingsInterface.setGenerateGeometryOnCheckin(false);
        final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface().getDeserializerByName("IfcStepDeserializer");
        Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
        serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true);
        final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid());
        ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000));
        for (int i = 0; i < 20; i++) {
            executor.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        ServiceMap serviceMap2 = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL);
                        SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap.getServiceInterface().getSerializerByName("Ifc2x3");
                        Long download = serviceMap2.getServiceInterface().download(Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true);
                        SDownloadResult downloadData = serviceMap2.getServiceInterface().getDownloadData(download);
                        if (downloadData.getFile().getDataSource() instanceof CacheStoringEmfSerializerDataSource) {
                            CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData.getFile().getDataSource();
                            try {
                                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                c.writeToOutputStream(baos, null);
                                System.out.println(baos.size());
                            } catch (SerializerException e) {
                                e.printStackTrace();
                            }
                        } else {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            IOUtils.copy(downloadData.getFile().getInputStream(), baos);
                            System.out.println(baos.size());
                        }
                        serviceMap2.getServiceInterface().cleanupLongAction(download);
                    } catch (ServerException e) {
                        e.printStackTrace();
                    } catch (UserException e) {
                        e.printStackTrace();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (PublicInterfaceNotFoundException e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.HOURS);
        bimServer.stop();
    } catch (ServerException e1) {
        e1.printStackTrace();
    } catch (UserException e1) {
        e1.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e2) {
        e2.printStackTrace();
    }
}
Also used : AuthInterface(org.bimserver.shared.interfaces.AuthInterface) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServiceMap(org.bimserver.webservices.ServiceMap) CacheStoringEmfSerializerDataSource(org.bimserver.plugins.serializers.CacheStoringEmfSerializerDataSource) FileNotFoundException(java.io.FileNotFoundException) DataHandler(javax.activation.DataHandler) BimServerConfig(org.bimserver.BimServerConfig) SProject(org.bimserver.interfaces.objects.SProject) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) FileDataSource(javax.activation.FileDataSource) UserException(org.bimserver.shared.exceptions.UserException) Path(java.nio.file.Path) ServerException(org.bimserver.shared.exceptions.ServerException) BimServer(org.bimserver.BimServer) PluginException(org.bimserver.shared.exceptions.PluginException) SDownloadResult(org.bimserver.interfaces.objects.SDownloadResult) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SerializerException(org.bimserver.plugins.serializers.SerializerException) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 8 with DatabaseInitException

use of org.bimserver.database.berkeley.DatabaseInitException in project BIMserver by opensourceBIM.

the class MemoryLeakTester method start.

public void start(int id, String address, int port, int pbport, Path[] pluginDirectories) {
    BimServerConfig config = new BimServerConfig();
    config.setHomeDir(Paths.get("home" + id));
    config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
    config.setStartEmbeddedWebServer(true);
    config.setClassPath(System.getProperty("java.class.path"));
    config.setStartCommandLine(false);
    config.setLocalDev(true);
    config.setPort(port);
    bimServer = new BimServer(config);
    bimServer.getVersionChecker().getLocalVersion().setDate(new Date());
    try {
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), pluginDirectories);
        bimServer.start();
        if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            AdminInterface adminInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(AdminInterface.class);
            adminInterface.setup("http://localhost:" + port, "Administrator", "admin@bimserver.org", "admin", null, null, null);
            SettingsInterface settingsInterface = bimServer.getServiceFactory().get(new SystemAuthorization(1, TimeUnit.HOURS), AccessMethod.INTERNAL).get(SettingsInterface.class);
            settingsInterface.setCacheOutputFiles(false);
        }
        bimServer.stop();
        bimServer = null;
        Thread.sleep(1000000);
    } catch (PluginException e) {
        LOGGER.error("", e);
    } catch (ServiceException e) {
        LOGGER.error("", e);
    } catch (DatabaseInitException e) {
        LOGGER.error("", e);
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } catch (DatabaseRestartRequiredException e) {
        LOGGER.error("", e);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : PluginException(org.bimserver.shared.exceptions.PluginException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) Date(java.util.Date) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException)

Aggregations

DatabaseInitException (org.bimserver.database.berkeley.DatabaseInitException)8 DatabaseRestartRequiredException (org.bimserver.database.DatabaseRestartRequiredException)7 PluginException (org.bimserver.shared.exceptions.PluginException)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 ServerException (org.bimserver.shared.exceptions.ServerException)4 Date (java.util.Date)3 BimServer (org.bimserver.BimServer)3 BimServerConfig (org.bimserver.BimServerConfig)3 InconsistentModelsException (org.bimserver.database.migrations.InconsistentModelsException)3 LocalDevelopmentResourceFetcher (org.bimserver.shared.LocalDevelopmentResourceFetcher)3 AdminInterface (org.bimserver.shared.interfaces.AdminInterface)3 SettingsInterface (org.bimserver.shared.interfaces.SettingsInterface)3 SystemAuthorization (org.bimserver.webservices.authorization.SystemAuthorization)3 Database (org.bimserver.database.Database)2 BerkeleyKeyValueStore (org.bimserver.database.berkeley.BerkeleyKeyValueStore)2 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)2 SProject (org.bimserver.interfaces.objects.SProject)2 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)2