Search in sources :

Example 1 with AdminInterface

use of org.bimserver.shared.interfaces.AdminInterface in project BIMserver by opensourceBIM.

the class TestInOut method start.

private void start(String[] args) {
    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("../")));
    BimServer bimServer = new BimServer(config);
    try {
        LocalDevPluginLoader.loadPlugins(bimServer.getPluginBundleManager(), new OptionsParser(args).getPluginDirectories());
        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:8080", "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);
        }
        BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
        SProject project = client.getServiceInterface().addProject("test", "ifc2x3tc1");
        SDeserializerPluginConfiguration deserializer = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        Path inputFile = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
        client.checkinSync(project.getOid(), "test", deserializer.getOid(), false, inputFile);
        project = client.getServiceInterface().getProjectByPoid(project.getOid());
        SSerializerPluginConfiguration serializer = client.getServiceInterface().getSerializerByContentType("application/ifc");
        Path outputFile = Paths.get("output.ifc");
        client.download(project.getLastRevisionId(), serializer.getOid(), outputFile);
        Diff diff = new Diff(false, false, false, inputFile, outputFile);
        diff.start();
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (DatabaseInitException e) {
        e.printStackTrace();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (DatabaseRestartRequiredException e) {
        e.printStackTrace();
    } catch (UserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (PublicInterfaceNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (CompareException e) {
        e.printStackTrace();
    } catch (BimServerClientException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServerException(org.bimserver.shared.exceptions.ServerException) Diff(org.bimserver.tests.diff.Diff) BimServer(org.bimserver.BimServer) PluginException(org.bimserver.shared.exceptions.PluginException) IOException(java.io.IOException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BimServerConfig(org.bimserver.BimServerConfig) OptionsParser(org.bimserver.plugins.OptionsParser) SProject(org.bimserver.interfaces.objects.SProject) BimServerClientException(org.bimserver.shared.exceptions.BimServerClientException) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) UserException(org.bimserver.shared.exceptions.UserException) CompareException(org.bimserver.tests.diff.CompareException)

Example 2 with AdminInterface

use of org.bimserver.shared.interfaces.AdminInterface 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 3 with AdminInterface

use of org.bimserver.shared.interfaces.AdminInterface 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.getPluginBundleManager(), 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)

Example 4 with AdminInterface

use of org.bimserver.shared.interfaces.AdminInterface in project BIMserver by opensourceBIM.

the class AbstractLocalDevBimServerStarter method start.

public void start(int id, String address, String name, int port, int pbport, Path[] pluginDirectories, Path home, ResourceFetcher resourceFetcher, String resourceBase, boolean autoSetup) {
    BimServerConfig config = new BimServerConfig();
    if (home != null) {
        config.setHomeDir(home);
    } else {
        config.setHomeDir(Paths.get("tmptestdata/home" + (id == -1 ? "" : id)));
    }
    config.setResourceFetcher(resourceFetcher);
    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.setResourceBase(resourceBase);
    Path bdbPropertiesFile = config.getHomeDir().resolve("bdb.properties");
    if (Files.exists(bdbPropertiesFile)) {
        try (InputStream inputStream = Files.newInputStream(bdbPropertiesFile)) {
            Properties properties = new Properties();
            properties.load(inputStream);
            config.setBdbEnvironmentProperties(properties);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    try {
        fixLogging(config);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    bimServer = new BimServer(config);
    bimServer.getVersionChecker().getLocalVersion().setDate(new Date());
    bimServer.setEmbeddedWebServer(new EmbeddedWebServer(bimServer, config.getResourcebase(), 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.getPluginBundleManager(), pluginDirectories);
                        } catch (PluginException e) {
                            LOGGER.error("", e);
                        }
                    }
                }
            });
        } else if (bimServer.getServerInfo().getServerState() == ServerState.RUNNING) {
            long start = System.nanoTime();
            LOGGER.info("Loading plugins...");
            LocalDevPluginLoader.loadPlugins(bimServer.getPluginBundleManager(), pluginDirectories);
            bimServer.activateServices();
            long end = System.nanoTime();
            LOGGER.info("All plugins loaded (" + ((end - start) / 1000000) + " ms)");
        } else if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
            LocalDevPluginLoader.loadPlugins(bimServer.getPluginBundleManager(), pluginDirectories);
            if (autoSetup) {
                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 : Path(java.nio.file.Path) InputStream(java.io.InputStream) ServerState(org.bimserver.models.store.ServerState) PluginException(org.bimserver.shared.exceptions.PluginException) IOException(java.io.IOException) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) Properties(java.util.Properties) Logger(org.slf4j.Logger) 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)

Aggregations

DatabaseRestartRequiredException (org.bimserver.database.DatabaseRestartRequiredException)4 DatabaseInitException (org.bimserver.database.berkeley.DatabaseInitException)4 PluginException (org.bimserver.shared.exceptions.PluginException)4 AdminInterface (org.bimserver.shared.interfaces.AdminInterface)4 SettingsInterface (org.bimserver.shared.interfaces.SettingsInterface)4 SystemAuthorization (org.bimserver.webservices.authorization.SystemAuthorization)4 IOException (java.io.IOException)3 Date (java.util.Date)3 LocalDevelopmentResourceFetcher (org.bimserver.shared.LocalDevelopmentResourceFetcher)3 ServiceException (org.bimserver.shared.exceptions.ServiceException)3 Path (java.nio.file.Path)2 ServerState (org.bimserver.models.store.ServerState)2 Logger (org.slf4j.Logger)2 InputStream (java.io.InputStream)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Properties (java.util.Properties)1 BimServer (org.bimserver.BimServer)1 BimServerConfig (org.bimserver.BimServerConfig)1 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)1