예제 #1
0
 public static String getTenantDomainFromId(int tid) {
   SuperTenantCarbonContext.startTenantFlow();
   SuperTenantCarbonContext.getCurrentContext().setTenantId(tid);
   String tenantDomain = SuperTenantCarbonContext.getCurrentContext().getTenantDomain();
   SuperTenantCarbonContext.endTenantFlow();
   return tenantDomain;
 }
  public void terminatingConfigurationContext(ConfigurationContext configurationContext) {
    String tenantDomain =
        SuperTenantCarbonContext.getCurrentContext(configurationContext).getTenantDomain();

    log.info("Shutting down the persistence manager for the tenant: " + tenantDomain);

    Parameter p =
        configurationContext
            .getAxisConfiguration()
            .getParameter(ServiceBusConstants.PERSISTENCE_MANAGER);
    if (p != null && p.getValue() instanceof MediationPersistenceManager) {
      ((MediationPersistenceManager) p.getValue()).destroy();
    }

    // unregister the service so that components get to know about the tenant termination
    int tenantId = SuperTenantCarbonContext.getCurrentContext(configurationContext).getTenantId();
    ServiceRegistration tenantRegistration =
        ConfigurationHolder.getInstance().getSynapseRegistration(tenantId);

    if (tenantRegistration != null) {
      ConfigurationHolder.getInstance()
          .getBundleContext()
          .ungetService(tenantRegistration.getReference());
    }
  }
예제 #3
0
 public void onLogin(Registry configSystemRegistry, LoginEvent loginEvent) {
   try {
     if (initializedTenants.contains(loginEvent.getTenantId())) {
       return;
     }
     initializedTenants.add(loginEvent.getTenantId());
     SuperTenantCarbonContext.startTenantFlow();
     try {
       SuperTenantCarbonContext.getCurrentContext().setTenantId(loginEvent.getTenantId());
       SuperTenantCarbonContext.getCurrentContext().setUsername(loginEvent.getUsername());
       CommonUtil.addDefaultHandlersIfNotAvailable(configSystemRegistry);
     } finally {
       SuperTenantCarbonContext.endTenantFlow();
     }
   } catch (Exception e) {
     String msg = "Error in adding the default handlers";
     log.error(msg, e);
   }
 }
  private void initPersistence(
      String configName,
      ConfigurationContext configurationContext,
      ServerContextInformation contextInfo)
      throws RegistryException, AxisFault {
    // Initialize the mediation persistence manager if required
    ServerConfiguration serverConf = ServerConfiguration.getInstance();
    String persistence = serverConf.getFirstProperty(ServiceBusConstants.PERSISTENCE);
    org.wso2.carbon.registry.core.Registry configRegistry =
        (org.wso2.carbon.registry.core.Registry)
            SuperTenantCarbonContext.getCurrentContext(configurationContext)
                .getRegistry(RegistryType.SYSTEM_CONFIGURATION);

    // Check whether persistence is disabled
    if (!ServiceBusConstants.DISABLED.equals(persistence)) {

      // Check registry persistence is disabled or not
      String regPersistence = serverConf.getFirstProperty(ServiceBusConstants.REGISTRY_PERSISTENCE);
      UserRegistry registry =
          ServiceBusConstants.DISABLED.equals(regPersistence)
              ? null
              : (UserRegistry) configRegistry;

      // Check the worker interval is set or not
      String interval = serverConf.getFirstProperty(ServiceBusConstants.WORKER_INTERVAL);
      long intervalInMillis = 5000L;
      if (interval != null && !"".equals(interval)) {
        try {
          intervalInMillis = Long.parseLong(interval);
        } catch (NumberFormatException e) {
          log.error(
              "Invalid value "
                  + interval
                  + " specified for the mediation "
                  + "persistence worker interval, Using defaults",
              e);
        }
      }

      MediationPersistenceManager pm =
          new MediationPersistenceManager(
              registry,
              contextInfo.getServerConfigurationInformation().getSynapseXMLLocation(),
              contextInfo.getSynapseConfiguration(),
              intervalInMillis,
              configName);

      configurationContext
          .getAxisConfiguration()
          .addParameter(new Parameter(ServiceBusConstants.PERSISTENCE_MANAGER, pm));
    } else {
      log.info("Persistence for mediation configuration is disabled");
    }
  }
  public void createdConfigurationContext(ConfigurationContext configurationContext) {
    ServerContextInformation contextInfo;
    String tenantDomain =
        SuperTenantCarbonContext.getCurrentContext(configurationContext).getTenantDomain();

    log.info("Intializing the ESB Configuration for the tenant domain : " + tenantDomain);

    try {
      // first check which configuration should be active
      org.wso2.carbon.registry.core.Registry registry =
          (org.wso2.carbon.registry.core.Registry)
              SuperTenantCarbonContext.getCurrentContext(configurationContext)
                  .getRegistry(RegistryType.SYSTEM_CONFIGURATION);

      AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();

      // initialize the lock
      Lock lock = new ReentrantLock();
      axisConfig.addParameter(ServiceBusConstants.SYNAPSE_CONFIG_LOCK, lock);

      // creates the synapse configuration directory hierarchy if not exists
      // useful at the initial tenant creation
      File tenantAxis2Repo =
          new File(configurationContext.getAxisConfiguration().getRepository().getFile());
      File synapseConfigsDir = new File(tenantAxis2Repo, ServiceBusConstants.SYNAPSE_CONFIGS);
      if (!synapseConfigsDir.exists()) {
        if (!synapseConfigsDir.mkdir()) {
          log.fatal(
              "Couldn't create the synapse-config root on the file system "
                  + "for the tenant domain : "
                  + tenantDomain);
          return;
        }
      }

      String synapseConfigsDirLocation = synapseConfigsDir.getAbsolutePath();

      // set the required configuration parameters to initialize the ESB
      axisConfig.addParameter(
          SynapseConstants.Axis2Param.SYNAPSE_CONFIG_LOCATION, synapseConfigsDirLocation);

      // init the multiple configuration tracker
      ConfigurationManager manger =
          new ConfigurationManager((UserRegistry) registry, configurationContext);
      manger.init();

      File synapseConfigDir =
          new File(synapseConfigsDir, manger.getTracker().getCurrentConfigurationName());
      if (!synapseConfigDir.exists()) {
        createTenantSynapseConfigHierarchy(synapseConfigDir, tenantDomain);
      }

      axisConfig.addParameter(
          SynapseConstants.Axis2Param.SYNAPSE_HOME, tenantAxis2Repo.getAbsolutePath());
      axisConfig.addParameter(
          SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME, "synapse." + tenantDomain);
      axisConfig.addParameter(
          SynapseConstants.Axis2Param.SYNAPSE_RESOLVE_ROOT, tenantAxis2Repo.getAbsolutePath());

      // Initialize Synapse
      contextInfo =
          initESB(manger.getTracker().getCurrentConfigurationName(), configurationContext);

      if (contextInfo == null) {
        handleFatal("Failed to intilize the ESB for tenent:" + tenantDomain);
      }

      initPersistence(
          manger.getTracker().getCurrentConfigurationName(), configurationContext, contextInfo);

      configurationContext.setProperty(ConfigurationManager.CONFIGURATION_MANAGER, manger);

      int tenantId = SuperTenantCarbonContext.getCurrentContext(configurationContext).getTenantId();
      // populate the SynapseEnv service and SynapseConfig OSGI Services so that other
      // components get to know about the availability of the new synapse configuration
      Properties props = new Properties();
      SynapseConfigurationService synCfgSvc =
          new SynapseConfigurationServiceImpl(
              contextInfo.getSynapseConfiguration(), tenantId, configurationContext);

      ServiceRegistration confRegistration =
          ConfigurationHolder.getInstance()
              .getBundleContext()
              .registerService(SynapseConfigurationService.class.getName(), synCfgSvc, props);

      props = new Properties();
      SynapseEnvironmentService synEnvSvc =
          new SynapseEnvironmentServiceImpl(
              contextInfo.getSynapseEnvironment(), tenantId, configurationContext);
      ServiceRegistration envRegistration =
          ConfigurationHolder.getInstance()
              .getBundleContext()
              .registerService(SynapseEnvironmentService.class.getName(), synEnvSvc, props);

      props = new Properties();
      SynapseRegistrationsService synRegistrationsSvc =
          new SynapseRegistrationsServiceImpl(
              confRegistration, envRegistration, tenantId, configurationContext);
      ServiceRegistration synapseRegistration =
          ConfigurationHolder.getInstance()
              .getBundleContext()
              .registerService(
                  SynapseRegistrationsService.class.getName(), synRegistrationsSvc, props);

      ConfigurationTrackingService trackingService =
          ServiceBusInitializer.getConfigurationTrackingService();
      if (trackingService != null) {
        trackingService.setSynapseConfiguration(contextInfo.getSynapseConfiguration());
      }

      // set the event broker as a property for tenants
      EventBroker eventBroker = ServiceBusInitializer.getEventBroker();
      if (eventBroker != null) {
        configurationContext.setProperty("mediation.event.broker", eventBroker);
      }

      ConfigurationHolder.getInstance().addSynapseRegistration(tenantId, synapseRegistration);

    } catch (Exception e) {
      handleFatal("Couldn't initialize the ESB for tenant:" + tenantDomain, e);
    } catch (Throwable t) {
      log.fatal("Failed to initialize ESB for tenant:" + tenantDomain + "due to a fatal error", t);
    }
  }