use of org.bimserver.shared.pb.ProtocolBuffersMetaData in project BIMserver by opensourceBIM.
the class BimServer method initDatabaseDependantItems.
private void initDatabaseDependantItems() throws BimserverDatabaseException {
LOGGER.info("Initializing database dependant logic...");
long start = System.nanoTime();
notificationsManager.init();
getSerializerFactory().init(pluginManager, bimDatabase, this);
try {
DatabaseSession session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE);
try {
updatePlugins(session);
session.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
} finally {
session.close();
}
int renderEngineProcesses = getServerSettingsCache().getServerSettings().getRenderEngineProcesses();
RenderEnginePoolFactory renderEnginePoolFactory = new CommonsPoolingRenderEnginePoolFactory(renderEngineProcesses);
renderEnginePools = new RenderEnginePools(this, renderEnginePoolFactory);
session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE);
// createDatabaseObjects(session);
ServerSettings serverSettings = serverSettingsCache.getServerSettings();
for (Entry<PluginContext, WebModulePlugin> entry : pluginManager.getAllWebPlugins(true).entrySet()) {
WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), entry.getKey().getIdentifier());
if (webPluginConfiguration == null) {
webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
serverSettings.getWebModules().add(webPluginConfiguration);
PluginDescriptor pluginDescriptor = getPluginDescriptor(session, entry.getKey().getIdentifier());
if (pluginDescriptor == null) {
throw new BimserverDatabaseException("No plugin descriptor found: " + entry.getKey().getIdentifier());
}
genericPluginConversion(entry.getKey(), session, webPluginConfiguration, pluginDescriptor);
} else {
if (webPluginConfiguration == serverSettings.getWebModule()) {
setDefaultWebModule(entry.getValue());
}
}
}
// Set the default
// if (serverSettings.getWebModule() == null) {
// WebModulePluginConfiguration bimviewsWebModule = findWebModule(serverSettings, "BIM Views");
// if (bimviewsWebModule != null) {
// serverSettings.setWebModule(bimviewsWebModule);
// setDefaultWebModule(pluginManager.getWebModulePlugin(bimviewsWebModule.getPluginDescriptor().getPluginClassName(), true));
// } else {
// WebModulePluginConfiguration defaultWebModule = findWebModule(serverSettings, "org.bimserver.defaultwebmodule.DefaultWebModulePlugin");
// if (defaultWebModule != null) {
// serverSettings.setWebModule(defaultWebModule);
// setDefaultWebModule(pluginManager.getWebModulePlugin(defaultWebModule.getPluginDescriptor().getPluginClassName(), true));
// }
// }
// }
session.store(serverSettings);
Condition condition = new AttributeCondition(StorePackage.eINSTANCE.getUser_Username(), new StringLiteral("system"));
User systemUser = session.querySingle(condition, User.class, OldQuery.getDefault());
ServerStarted serverStarted = session.create(ServerStarted.class);
serverStarted.setDate(new Date());
serverStarted.setAccessMethod(AccessMethod.INTERNAL);
serverStarted.setExecutor(systemUser);
try {
session.store(serverStarted);
session.commit();
} catch (BimserverLockConflictException e) {
throw new BimserverDatabaseException(e);
} catch (ServiceException e) {
throw new BimserverDatabaseException(e);
} finally {
session.close();
}
webModules = new HashMap<String, WebModulePlugin>();
List<WebModulePluginConfiguration> webModuleConfigurations = serverSettingsCache.getServerSettings().getWebModules();
for (WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
String contextPath = "";
for (Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
if (parameter.getName().equals("contextPath")) {
contextPath = ((StringType) parameter.getValue()).getValue();
}
}
String identifier = webModulePluginConfiguration.getPluginDescriptor().getIdentifier();
webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
}
try (DatabaseSession databaseSession = getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
ExtendedDataSchema htmlSchema = (ExtendedDataSchema) databaseSession.querySingle(StorePackage.eINSTANCE.getExtendedDataSchema_Name(), "GEOMETRY_GENERATION_REPORT_HTML_1_1");
ExtendedDataSchema jsonSchema = (ExtendedDataSchema) databaseSession.querySingle(StorePackage.eINSTANCE.getExtendedDataSchema_Name(), "GEOMETRY_GENERATION_REPORT_JSON_1_1");
if (htmlSchema == null) {
htmlSchema = createExtendedDataSchema(databaseSession, "GEOMETRY_GENERATION_REPORT_HTML_1_1", "text/html");
}
if (jsonSchema == null) {
jsonSchema = createExtendedDataSchema(databaseSession, "GEOMETRY_GENERATION_REPORT_JSON_1_1", "application/json");
}
databaseSession.commit();
} catch (ServiceException e) {
LOGGER.error("", e);
}
Integer protocolBuffersPort = getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
try {
protocolBuffersMetaData = new ProtocolBuffersMetaData();
protocolBuffersMetaData.load(servicesMap, ProtocolBuffersBimServerClientFactory.class);
protocolBuffersServer = new ProtocolBuffersServer(protocolBuffersMetaData, serviceFactory, servicesMap, protocolBuffersPort);
protocolBuffersServer.start();
} catch (Exception e) {
LOGGER.error("", e);
}
}
bimServerClientFactory = new DirectBimServerClientFactory<ServiceInterface>(serverSettingsCache.getServerSettings().getSiteAddress(), serviceFactory, servicesMap, pluginManager, metaDataManager);
pluginManager.setBimServerClientFactory(bimServerClientFactory);
try (DatabaseSession session2 = bimDatabase.createSession(OperationType.READ_ONLY)) {
IfcModelInterface pluginBundleVersions = session2.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
for (PluginBundleVersion pluginBundleVersion : pluginBundleVersions.getAll(PluginBundleVersion.class)) {
if (pluginBundleVersion.getType() == PluginBundleType.MAVEN || pluginBundleVersion.getType() == PluginBundleType.LOCAL) {
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(pluginBundleVersion.getGroupId(), pluginBundleVersion.getArtifactId(), pluginBundleVersion.getVersion());
IfcModelInterface pluginDescriptors = session2.getAllOfType(StorePackage.eINSTANCE.getPluginDescriptor(), OldQuery.getDefault());
List<SPluginInformation> plugins = new ArrayList<>();
for (PluginDescriptor pluginDescriptor : pluginDescriptors.getAll(PluginDescriptor.class)) {
if (pluginDescriptor.getPluginBundleVersion() == pluginBundleVersion && pluginDescriptor.getEnabled()) {
SPluginInformation sPluginInformation = new SPluginInformation();
sPluginInformation.setEnabled(true);
sPluginInformation.setDescription(pluginDescriptor.getDescription());
sPluginInformation.setIdentifier(pluginDescriptor.getIdentifier());
sPluginInformation.setInstallForAllUsers(pluginDescriptor.isInstallForNewUsers());
sPluginInformation.setInstallForNewUsers(pluginDescriptor.isInstallForNewUsers());
sPluginInformation.setName(pluginDescriptor.getName());
sPluginInformation.setType(pluginManager.getPluginTypeFromClass(pluginDescriptor.getPluginClassName()));
plugins.add(sPluginInformation);
}
}
try {
pluginBundleManager.loadFromPluginDir(pluginBundleVersionIdentifier, getSConverter().convertToSObject(pluginBundleVersion), plugins, serverSettingsCache.getServerSettings().isPluginStrictVersionChecking());
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
} catch (Exception e) {
throw new BimserverDatabaseException(e);
}
} catch (BimserverLockConflictException e) {
throw new BimserverDatabaseException(e);
// } catch (PluginException e) {
// throw new BimserverDatabaseException(e);
} catch (RenderEngineException e) {
throw new BimserverDatabaseException(e);
}
long end = System.nanoTime();
LOGGER.info("Done initializing database dependant logic (" + ((end - start) / 1000000) + "ms)");
}
use of org.bimserver.shared.pb.ProtocolBuffersMetaData in project BIMserver by opensourceBIM.
the class ProtocolBuffersConnectionHandler method run.
@Override
public void run() {
try {
running = true;
while (running) {
String serviceName = dataInputStream.readUTF();
String methodName = dataInputStream.readUTF();
String token = dataInputStream.readUTF();
ProtocolBuffersMetaData protocolBuffersMetaData = protocolBuffersServer.getProtocolBuffersMetaData();
SService sService = servicesMap.getBySimpleName(serviceName);
if (sService == null) {
throw new UserException("No service found with name " + serviceName);
}
SMethod method = sService.getSMethod(methodName);
if (method == null) {
throw new UserException("Method " + methodName + " not found on " + serviceName);
}
Class<? extends PublicInterface> clazz = sService.getInterfaceClass();
PublicInterface service = null;
if (token.equals("")) {
service = serviceFactory.get(AccessMethod.PROTOCOL_BUFFERS).get(clazz);
} else {
service = serviceFactory.get(token, AccessMethod.PROTOCOL_BUFFERS).get(clazz);
}
ReflectiveRpcChannel reflectiveRpcChannel = new ReflectiveRpcChannel(clazz, service, protocolBuffersMetaData, servicesMap);
MethodDescriptorContainer pbMethod = protocolBuffersMetaData.getMethod(serviceName, methodName);
Builder requestBuilder = DynamicMessage.getDefaultInstance(pbMethod.getInputDescriptor()).newBuilderForType();
requestBuilder.mergeDelimitedFrom(dataInputStream);
Message response = reflectiveRpcChannel.callBlockingMethod(pbMethod, requestBuilder.build());
response.writeDelimitedTo(outputStream);
outputStream.flush();
}
} catch (SocketException e) {
} catch (EOFException e) {
} catch (Exception e) {
if (running) {
LOGGER.error("", e);
}
}
protocolBuffersServer.unregister(this);
}
Aggregations