private Map<String, String> buildReplacements(final STenant tenant) { return singletonMap("\\$\\{tenantid\\}", Long.toString(tenant.getId())); }
private Map<String, String> buildReplacements(final STenant tenant) { return singletonMap("\\$\\{tenantid\\}", Long.toString(tenant.getId())); }
private void addTenantJobListeners(PlatformServiceAccessor platformAccessor, final List<STenant> tenants, final SchedulerService schedulerService) throws SBonitaException, BonitaHomeNotSetException, IOException, BonitaHomeConfigurationException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { for (STenant tenant : tenants) { addTenantJobListener(platformAccessor, schedulerService, tenant.getId()); } }
private void addTenantJobListeners(PlatformServiceAccessor platformAccessor, final List<STenant> tenants, final SchedulerService schedulerService) throws SBonitaException, BonitaHomeNotSetException, IOException, BonitaHomeConfigurationException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { for (STenant tenant : tenants) { addTenantJobListener(platformAccessor, schedulerService, tenant.getId()); } }
@Override public void execute() throws SBonitaException { List<STenant> tenants; do { tenants = platformService.getTenants(new QueryOptions(0, 100, STenant.class, "id", OrderByType.ASC)); for (final STenant sTenant : tenants) { platformService.deactiveTenant(sTenant.getId()); platformService.deleteTenant(sTenant.getId()); } } while (tenants.size() > 0); } }
@Override public void execute() throws SBonitaException { List<STenant> tenants; do { tenants = platformService.getTenants(new QueryOptions(0, 100, STenant.class, "id", OrderByType.ASC)); for (final STenant sTenant : tenants) { platformService.deactiveTenant(sTenant.getId()); platformService.deleteTenant(sTenant.getId()); } } while (tenants.size() > 0); } }
@Override public Map<Long, Map<String, byte[]>> getClientTenantConfigurations() { try { PlatformService platformService = getPlatformAccessor().getPlatformService(); List<STenant> tenants = platformService.getTenants(QueryOptions.countQueryOptions()); HashMap<Long, Map<String, byte[]>> conf = new HashMap<>(); for (STenant tenant : tenants) { conf.put(tenant.getId(), getBonitaHomeServerInstance().getClientTenantConfigurations(tenant.getId())); } return conf; } catch (BonitaException | IOException | IllegalAccessException | ClassNotFoundException | InstantiationException | STenantException e) { throw new RetrieveException(e); } }
void afterServicesStartOfRestartHandlersOfTenant(final PlatformServiceAccessor platformAccessor, final Map<STenant, List<TenantRestartHandler>> tenantRestartHandlersOfTenants) { final NodeConfiguration platformConfiguration = platformAccessor.getPlatformConfiguration(); if (platformConfiguration.shouldResumeElements()) { // Here get all elements that are not "finished" // * FlowNodes that have flag: stateExecuting to true: call execute on them (connectors were executing) // * Process instances with token count == 0 (either not started again or finishing) -> same thing connectors were executing // * transitions that are in state created: call execute on them // * flow node that are completed and not deleted : call execute to make it create transitions and so on // * all element that are in not stable state for (Entry<STenant, List<TenantRestartHandler>> tenantRestartHandlers : tenantRestartHandlersOfTenants.entrySet()) { TenantServiceAccessor tenantServiceAccessor = platformAccessor.getTenantServiceAccessor(tenantRestartHandlers.getKey().getId()); new TenantRestarter(platformAccessor, tenantServiceAccessor).executeAfterServicesStart(tenantRestartHandlers.getValue()); } } }
void afterServicesStartOfRestartHandlersOfTenant(final PlatformServiceAccessor platformAccessor, final Map<STenant, List<TenantRestartHandler>> tenantRestartHandlersOfTenants) { final NodeConfiguration platformConfiguration = platformAccessor.getPlatformConfiguration(); if (platformConfiguration.shouldResumeElements()) { // Here get all elements that are not "finished" // * FlowNodes that have flag: stateExecuting to true: call execute on them (connectors were executing) // * Process instances with token count == 0 (either not started again or finishing) -> same thing connectors were executing // * transitions that are in state created: call execute on them // * flow node that are completed and not deleted : call execute to make it create transitions and so on // * all element that are in not stable state for (Entry<STenant, List<TenantRestartHandler>> tenantRestartHandlers : tenantRestartHandlersOfTenants.entrySet()) { TenantServiceAccessor tenantServiceAccessor = platformAccessor.getTenantServiceAccessor(tenantRestartHandlers.getKey().getId()); new TenantRestarter(platformAccessor, tenantServiceAccessor).executeAfterServicesStart(tenantRestartHandlers.getValue()); } } }
@Override public Map<Long, Map<String, byte[]>> getClientTenantConfigurations() { try { PlatformService platformService = getPlatformAccessor().getPlatformService(); List<STenant> tenants = platformService.getTenants(QueryOptions.countQueryOptions()); HashMap<Long, Map<String, byte[]>> conf = new HashMap<>(); for (STenant tenant : tenants) { conf.put(tenant.getId(), getBonitaHomeServerInstance().getClientTenantConfigurations(tenant.getId())); } return conf; } catch (BonitaException | IOException | IllegalAccessException | ClassNotFoundException | InstantiationException | STenantException e) { throw new RetrieveException(e); } }
public static long createTenant(final TransactionService transactionService, final PlatformService platformService, final String tenantName, final String createdBy, final String status) throws Exception { try { transactionService.begin(); final long created = System.currentTimeMillis(); final STenantBuilder tenantBuilder = BuilderFactory.get(STenantBuilderFactory.class).createNewInstance(tenantName, createdBy, created, status, false); final STenant tenant = tenantBuilder.done(); platformService.createTenant(tenant); BonitaHomeServer.getInstance().createTenant(tenant.getId()); platformService.activateTenant(tenant.getId()); return tenant.getId(); } finally { transactionService.complete(); } }
public static long createDefaultTenant(final TransactionService transactionService, final PlatformService platformService, final String tenantName, final String createdBy, final String status) throws Exception { try { transactionService.begin(); final long created = System.currentTimeMillis(); final STenantBuilder tenantBuilder = BuilderFactory.get(STenantBuilderFactory.class) .createNewInstance(tenantName, createdBy, created, status, true); final STenant tenant = tenantBuilder.done(); platformService.createTenant(tenant); BonitaHomeServer.getInstance().createTenant(tenant.getId()); platformService.activateTenant(tenant.getId()); return tenant.getId(); } finally { transactionService.complete(); } } }
protected void checkThatWeCanLogin(final String userName, final STenant sTenant, TechnicalUser technicalUser) throws LoginException { if (!sTenant.isActivated()) { throw new LoginException("Tenant " + sTenant.getName() + " is not activated !!"); } if (sTenant.isPaused()) { final String technicalUserName = technicalUser.getUserName(); if (!technicalUserName.equals(userName)) { throw new TenantStatusException("Tenant with ID " + sTenant.getId() + " is in pause, unable to login with other user than the technical user."); } } }
protected APISession loginInternal(final Long tenantId, final Map<String, Serializable> credentials) throws Exception { final String userName = credentials.get(AuthenticationConstants.BASIC_USERNAME) != null ? String.valueOf(credentials .get(AuthenticationConstants.BASIC_USERNAME)) : null; final PlatformServiceAccessor platformServiceAccessor = ServiceAccessorFactory.getInstance().createPlatformServiceAccessor(); final STenant sTenant = getTenant(tenantId, platformServiceAccessor); final TenantServiceAccessor serviceAccessor = getTenantServiceAccessor(sTenant.getId()); checkThatWeCanLogin(userName, sTenant, serviceAccessor.getTechnicalUser()); final LoginService loginService = serviceAccessor.getLoginService(); final TransactionService transactionService = platformServiceAccessor.getTransactionService(); SessionAccessor sessionAccessor = serviceAccessor.getSessionAccessor(); final Map<String, Serializable> credentialsWithResolvedTenantId = new HashMap<>(credentials); credentialsWithResolvedTenantId.put(AuthenticationConstants.BASIC_TENANT_ID, sTenant.getId()); sessionAccessor.setTenantId(sTenant.getId()); try { final SSession sSession = transactionService.executeInTransaction(() -> loginService.login(credentialsWithResolvedTenantId)); return ModelConvertor.toAPISession(sSession, sTenant.getName()); } catch (Exception e) { //avoid brut force... (should be done differently, but it is the behavior since 6.0.0) Thread.sleep(3000); throw e; } }
protected void checkThatWeCanLogin(final String userName, final STenant sTenant, TechnicalUser technicalUser) throws LoginException { if (!sTenant.isActivated()) { throw new LoginException("Tenant " + sTenant.getName() + " is not activated !!"); } if (sTenant.isPaused()) { final String technicalUserName = technicalUser.getUserName(); if (!technicalUserName.equals(userName)) { throw new TenantStatusException("Tenant with ID " + sTenant.getId() + " is in pause, unable to login with other user than the technical user."); } } }
@Override public long createTenant(final STenant tenant) throws STenantCreationException, STenantAlreadyExistException { if (isTraced) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogBeforeMethod(this.getClass(), LOG_CREATE_TENANT)); } // check if the tenant already exists. If yes, throws TenantAlreadyExistException checkIfTenantAlreadyExists(tenant); // create the tenant try { recorder.recordInsert(new InsertRecord(tenant), TENANT); } catch (final SRecorderException e) { if (isTraced) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogOnExceptionMethod(this.getClass(), LOG_CREATE_TENANT, e)); } throw new STenantCreationException("Unable to insert the tenant row : " + e.getMessage(), e); } initializeTenant(tenant); return tenant.getId(); }
@Override public long createTenant(final STenant tenant) throws STenantCreationException, STenantAlreadyExistException { if (isTraced) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogBeforeMethod(this.getClass(), LOG_CREATE_TENANT)); } // check if the tenant already exists. If yes, throws TenantAlreadyExistException checkIfTenantAlreadyExists(tenant); // create the tenant try { recorder.recordInsert(new InsertRecord(tenant), TENANT); } catch (final SRecorderException e) { if (isTraced) { logger.log(this.getClass(), TechnicalLogSeverity.TRACE, LogUtil.getLogOnExceptionMethod(this.getClass(), LOG_CREATE_TENANT, e)); } throw new STenantCreationException("Unable to insert the tenant row : " + e.getMessage(), e); } initializeTenant(tenant); return tenant.getId(); }
@Override public void run() { final TechnicalLoggerService technicalLoggerService = tenantServiceAccessor.getTechnicalLoggerService(); try { final long tenantId = tenantServiceAccessor.getTenantId(); SessionAccessor sessionAccessor = tenantServiceAccessor.getSessionAccessor(); STenant tenant = getTenant(tenantId); technicalLoggerService.log(getClass(), TechnicalLogSeverity.INFO, "Restarting elements of tenant " + tenant.getId() + " that were not finished at the last shutdown"); if (tenant.isPaused() || !tenant.isActivated()) { technicalLoggerService.log(getClass(), TechnicalLogSeverity.WARNING, "Unable to restart elements of tenant " + tenant.getStatus()); return; } executeHandlers(tenantId, sessionAccessor); } catch (Exception e) { technicalLoggerService.log(StarterThread.class, TechnicalLogSeverity.ERROR, "Error while restarting elements", e); } }
@Override public void run() { final TechnicalLoggerService technicalLoggerService = tenantServiceAccessor.getTechnicalLoggerService(); try { final long tenantId = tenantServiceAccessor.getTenantId(); SessionAccessor sessionAccessor = tenantServiceAccessor.getSessionAccessor(); STenant tenant = getTenant(tenantId); technicalLoggerService.log(getClass(), TechnicalLogSeverity.INFO, "Restarting elements of tenant " + tenant.getId() + " that were not finished at the last shutdown"); if (tenant.isPaused() || !tenant.isActivated()) { technicalLoggerService.log(getClass(), TechnicalLogSeverity.WARNING, "Unable to restart elements of tenant " + tenant.getStatus()); return; } executeHandlers(tenantId, sessionAccessor); } catch (Exception e) { technicalLoggerService.log(StarterThread.class, TechnicalLogSeverity.ERROR, "Error while restarting elements", e); } }
void startServicesOfTenants(final PlatformServiceAccessor platformAccessor, final SessionAccessor sessionAccessor, final List<STenant> tenants) throws Exception { for (final STenant tenant : tenants) { final long tenantId = tenant.getId(); if (!tenant.isPaused() && tenant.isActivated()) { final SessionService sessionService = platformAccessor.getTenantServiceAccessor(tenantId).getSessionService(); long sessionId = -1; long platformSessionId = -1; try { platformSessionId = sessionAccessor.getSessionId(); sessionAccessor.deleteSessionId(); sessionId = createSessionAndMakeItActive(platformAccessor, sessionAccessor, tenantId); final SetServiceState startService = new SetServiceState(tenantId, new StartServiceStrategy()); platformAccessor.getTransactionService().executeInTransaction(startService); } finally { sessionService.deleteSession(sessionId); cleanSessionAccessor(sessionAccessor, platformSessionId); } } } }