Search in sources :

Example 1 with SystemLauncher

use of org.apache.qpid.server.SystemLauncher in project qpid-broker-j by apache.

the class InternalBrokerHolder method start.

public void start(final Map<String, Object> systemConfig) throws Exception {
    if (Thread.getDefaultUncaughtExceptionHandler() == null) {
        Thread.setDefaultUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER);
    }
    LOGGER.info("Starting internal broker (same JVM)");
    _systemLauncher = new SystemLauncher(new LogbackLoggingSystemLauncherListener(), new SystemLauncherListener.DefaultSystemLauncherListener() {

        @Override
        public void onShutdown(final int exitCode) {
            _systemLauncher = null;
        }

        @Override
        public void exceptionOnShutdown(final Exception e) {
            if (e instanceof IllegalStateException || e instanceof IllegalStateTransitionException) {
                System.out.println("IllegalStateException occurred on broker shutdown in test " + getClassQualifiedTestName());
            }
        }
    });
    _systemLauncher.startup(systemConfig);
}
Also used : SystemLauncher(org.apache.qpid.server.SystemLauncher) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException)

Example 2 with SystemLauncher

use of org.apache.qpid.server.SystemLauncher in project beam by apache.

the class RabbitMqIOTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    port = NetworkTestHelper.getAvailableLocalPort();
    defaultPort = System.getProperty("qpid.amqp_port");
    System.setProperty("qpid.amqp_port", "" + port);
    System.setProperty("derby.stream.error.field", "MyApp.DEV_NULL");
    // see https://stackoverflow.com/a/49234754/796064 for qpid setup
    launcher = new SystemLauncher();
    Map<String, Object> attributes = new HashMap<>();
    URL initialConfig = RabbitMqIOTest.class.getResource("rabbitmq-io-test-config.json");
    attributes.put("type", "Memory");
    attributes.put("initialConfigurationLocation", initialConfig.toExternalForm());
    attributes.put(SystemConfig.DEFAULT_QPID_WORK_DIR, temporaryFolder.newFolder().toString());
    launcher.startup(attributes);
}
Also used : SystemLauncher(org.apache.qpid.server.SystemLauncher) HashMap(java.util.HashMap) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 3 with SystemLauncher

use of org.apache.qpid.server.SystemLauncher in project qpid-broker-j by apache.

the class SNITest method doBrokerStartup.

private void doBrokerStartup(boolean useMatching, String defaultAlias, final boolean ignoreInvalidSni) throws Exception {
    final File initialConfiguration = createInitialContext();
    _brokerWork = TestFileUtils.createTestDirectory("qpid-work", true);
    Map<String, String> context = new HashMap<>();
    context.put("qpid.work_dir", _brokerWork.toString());
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(SystemConfig.INITIAL_CONFIGURATION_LOCATION, initialConfiguration.getAbsolutePath());
    attributes.put(SystemConfig.TYPE, JsonSystemConfigImpl.SYSTEM_CONFIG_TYPE);
    attributes.put(SystemConfig.CONTEXT, context);
    _systemLauncher = new SystemLauncher(new DefaultSystemLauncherListener() {

        @Override
        public void onContainerResolve(final SystemConfig<?> systemConfig) {
            _broker = systemConfig.getContainer(Broker.class);
        }
    });
    _systemLauncher.startup(attributes);
    final Map<String, Object> authProviderAttr = new HashMap<>();
    authProviderAttr.put(AuthenticationProvider.NAME, "myAuthProvider");
    authProviderAttr.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
    final AuthenticationProvider authProvider = _broker.createChild(AuthenticationProvider.class, authProviderAttr);
    Map<String, Object> keyStoreAttr = new HashMap<>();
    keyStoreAttr.put(FileKeyStore.NAME, "myKeyStore");
    keyStoreAttr.put(FileKeyStore.STORE_URL, _keyStoreFile.toURI().toURL().toString());
    keyStoreAttr.put(FileKeyStore.PASSWORD, TLS_RESOURCE.getSecret());
    keyStoreAttr.put(FileKeyStore.USE_HOST_NAME_MATCHING, useMatching);
    keyStoreAttr.put(FileKeyStore.CERTIFICATE_ALIAS, defaultAlias);
    final KeyStore keyStore = _broker.createChild(KeyStore.class, keyStoreAttr);
    Map<String, Object> portAttr = new HashMap<>();
    portAttr.put(Port.NAME, "myPort");
    portAttr.put(Port.TYPE, "AMQP");
    portAttr.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
    portAttr.put(Port.PORT, 0);
    portAttr.put(Port.AUTHENTICATION_PROVIDER, authProvider);
    portAttr.put(Port.KEY_STORE, keyStore);
    portAttr.put(Port.CONTEXT, Collections.singletonMap(AmqpPort.PORT_IGNORE_INVALID_SNI, String.valueOf(ignoreInvalidSni)));
    final Port<?> port = _broker.createChild(Port.class, portAttr);
    _boundPort = port.getBoundPort();
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) FileKeyStore(org.apache.qpid.server.security.FileKeyStore) KeyStore(org.apache.qpid.server.model.KeyStore) SystemLauncher(org.apache.qpid.server.SystemLauncher) DefaultSystemLauncherListener(org.apache.qpid.server.SystemLauncherListener.DefaultSystemLauncherListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) File(java.io.File)

Example 4 with SystemLauncher

use of org.apache.qpid.server.SystemLauncher in project qpid-broker-j by apache.

the class EmbeddedBrokerPerClassAdminImpl method beforeTestClass.

@Override
public void beforeTestClass(final Class testClass) {
    _preservedProperties = new HashMap<>();
    try {
        String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
        _currentWorkDirectory = Files.createTempDirectory(String.format("qpid-work-%s-%s-", timestamp, testClass.getSimpleName())).toString();
        ConfigItem[] configItems = (ConfigItem[]) testClass.getAnnotationsByType(ConfigItem.class);
        Arrays.stream(configItems).filter(ConfigItem::jvm).forEach(i -> {
            _preservedProperties.put(i.name(), System.getProperty(i.name()));
            System.setProperty(i.name(), i.value());
        });
        Map<String, String> context = new HashMap<>();
        context.put("qpid.work_dir", _currentWorkDirectory);
        context.put("qpid.port.protocol_handshake_timeout", "1000000");
        context.putAll(Arrays.stream(configItems).filter(i -> !i.jvm()).collect(Collectors.toMap(ConfigItem::name, ConfigItem::value, (name, value) -> value)));
        Map<String, Object> systemConfigAttributes = new HashMap<>();
        systemConfigAttributes.put(ConfiguredObject.CONTEXT, context);
        systemConfigAttributes.put(ConfiguredObject.TYPE, System.getProperty("broker.config-store-type", "JSON"));
        systemConfigAttributes.put(SystemConfig.STARTUP_LOGGED_TO_SYSTEM_OUT, Boolean.FALSE);
        if (Thread.getDefaultUncaughtExceptionHandler() == null) {
            Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
        }
        LOGGER.info("Starting internal broker (same JVM)");
        List<SystemLauncherListener> systemLauncherListeners = new ArrayList<>();
        systemLauncherListeners.add(new LogbackLoggingSystemLauncherListener());
        systemLauncherListeners.add(new ShutdownLoggingSystemLauncherListener());
        systemLauncherListeners.add(new PortExtractingLauncherListener());
        _systemLauncher = new SystemLauncher(systemLauncherListeners.toArray(new SystemLauncherListener[systemLauncherListeners.size()]));
        _systemLauncher.startup(systemConfigAttributes);
    } catch (Exception e) {
        throw new BrokerAdminException("Failed to start broker for test class", e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) NotFoundException(org.apache.qpid.server.model.NotFoundException) SystemLauncherListener(org.apache.qpid.server.SystemLauncherListener) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) SystemLauncher(org.apache.qpid.server.SystemLauncher) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with SystemLauncher

use of org.apache.qpid.server.SystemLauncher in project qpid-broker-j by apache.

the class AESGCMKeyFileEncrypterTest method createBrokerAndAuthenticationProviderWithEncrypterPassword.

private void createBrokerAndAuthenticationProviderWithEncrypterPassword(final Object encryptionType, final Path workDir, final Map<String, String> brokerContext) throws Exception {
    _workDir = workDir;
    final Map<String, String> context = new HashMap<>();
    context.put("qpid.work_dir", workDir.toFile().getAbsolutePath());
    _configurationLocation = Files.createTempFile(_workDir, "config", ".json");
    final Map<String, Object> config = new HashMap<>();
    config.put(ConfiguredObject.NAME, getTestName());
    config.put(Broker.MODEL_VERSION, BrokerModel.MODEL_VERSION);
    config.put(Broker.CONFIDENTIAL_CONFIGURATION_ENCRYPTION_PROVIDER, encryptionType);
    config.put(Broker.CONTEXT, brokerContext);
    new ObjectMapper().writeValue(_configurationLocation.toFile(), config);
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put("storePath", _configurationLocation.toFile().getAbsolutePath());
    attributes.put("preferenceStoreAttributes", "{\"type\": \"Noop\"}");
    attributes.put(SystemConfig.TYPE, JsonSystemConfigImpl.SYSTEM_CONFIG_TYPE);
    attributes.put(SystemConfig.STARTUP_LOGGED_TO_SYSTEM_OUT, Boolean.FALSE);
    attributes.put(SystemConfig.CONTEXT, context);
    final SettableFuture<SystemConfig<?>> configFuture = SettableFuture.create();
    _systemLauncher = new SystemLauncher(new SystemLauncherListener.DefaultSystemLauncherListener() {

        @Override
        public void onContainerResolve(final SystemConfig<?> systemConfig) {
            configFuture.set(systemConfig);
        }
    });
    _systemLauncher.startup(attributes);
    final SystemConfig<?> systemConfig = configFuture.get(BROKER_START_TIMEOUT, TimeUnit.SECONDS);
    _broker = (Broker<?>) systemConfig.getContainer();
    final Map<String, Object> authProviderAttributes = new HashMap<>();
    authProviderAttributes.put(ConfiguredObject.NAME, "testAuthProvider");
    authProviderAttributes.put(ConfiguredObject.TYPE, "Plain");
    final AuthenticationProvider<?> authProvider = _broker.createChild(AuthenticationProvider.class, authProviderAttributes);
    final Map<String, Object> userAttrs = new HashMap<>();
    userAttrs.put(User.TYPE, "managed");
    userAttrs.put(User.NAME, "guest");
    userAttrs.put(User.PASSWORD, SECRET);
    authProvider.createChild(User.class, userAttrs);
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) SystemLauncher(org.apache.qpid.server.SystemLauncher) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

SystemLauncher (org.apache.qpid.server.SystemLauncher)5 HashMap (java.util.HashMap)4 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 LogbackLoggingSystemLauncherListener (org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener)2 IllegalStateTransitionException (org.apache.qpid.server.model.IllegalStateTransitionException)2 SystemConfig (org.apache.qpid.server.model.SystemConfig)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 URL (java.net.URL)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 SystemLauncherListener (org.apache.qpid.server.SystemLauncherListener)1 DefaultSystemLauncherListener (org.apache.qpid.server.SystemLauncherListener.DefaultSystemLauncherListener)1 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)1 Broker (org.apache.qpid.server.model.Broker)1 KeyStore (org.apache.qpid.server.model.KeyStore)1 NotFoundException (org.apache.qpid.server.model.NotFoundException)1 FileKeyStore (org.apache.qpid.server.security.FileKeyStore)1 BeforeClass (org.junit.BeforeClass)1