Search in sources :

Example 36 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by jboss-fuse.

the class DownloadManagers method createDownloadManager.

/**
 * Creates a download manager using the current container's maven configuration
 */
public static DownloadManager createDownloadManager(FabricService fabricService, ScheduledExecutorService executorService) {
    Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile();
    Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
    return createDownloadManager(fabricService, effectiveProfile, executorService);
}
Also used : Profile(io.fabric8.api.Profile)

Example 37 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by jboss-fuse.

the class BootstrapConfiguration method configureInternal.

void configureInternal(Map<String, ?> conf) throws Exception {
    configuration = configurer.configure(conf, this);
    if (Strings.isNullOrBlank(runtimeId)) {
        throw new IllegalArgumentException("Runtime id must not be null or empty.");
    }
    if (Strings.isNullOrBlank(localResolver)) {
        localResolver = globalResolver;
    }
    String decodedZookeeperPassword = null;
    Properties userProps = new Properties();
    try {
        userProps.load(new File(confDir, "users.properties"));
    } catch (IOException e) {
        LOGGER.warn("Failed to load users from etc/users.properties. No users will be imported.", e);
    }
    if (Strings.isNotBlank(zookeeperPassword)) {
        decodedZookeeperPassword = PasswordEncoder.decode(zookeeperPassword);
    } else if (userProps.containsKey(DEFAULT_ADMIN_USER)) {
        String passwordAndRole = userProps.getProperty(DEFAULT_ADMIN_USER).trim();
        decodedZookeeperPassword = passwordAndRole.substring(0, passwordAndRole.indexOf(ROLE_DELIMITER));
    } else {
        decodedZookeeperPassword = PasswordEncoder.encode(CreateEnsembleOptions.generatePassword());
    }
    // do not trigger io.fabric8.zookeeper update if restart is pending (fabric:join)
    if (!Boolean.getBoolean("karaf.restart") && zookeeperUrl != null && zookeeperPassword != null) {
        Configuration zkConfugiration = configAdmin.get().getConfiguration(Constants.ZOOKEEPER_CLIENT_PID);
        if (zkConfugiration.getProperties() == null) {
            Hashtable<String, Object> zkProperties = new Hashtable<>();
            zkProperties.put("zookeeper.url", zookeeperUrl);
            zkProperties.put("zookeeper.password", PasswordEncoder.encode(decodedZookeeperPassword));
            zkConfugiration.update(zkProperties);
        }
    }
    if (userProps.isEmpty()) {
        userProps.put(DEFAULT_ADMIN_USER, decodedZookeeperPassword + ROLE_DELIMITER + DEFAULT_ADMIN_ROLE);
    }
    String minimumPort = (String) configuration.get("minimum.port");
    if (!Strings.isNullOrBlank(minimumPort)) {
        this.minport = Integer.valueOf(minimumPort);
    }
    String maximumPort = (String) configuration.get("maximum.port");
    if (!Strings.isNullOrBlank(maximumPort)) {
        this.maxport = Integer.valueOf(maximumPort);
    }
    options = CreateEnsembleOptions.builder().bindAddress(bindAddress).agentEnabled(agentAutoStart).ensembleStart(ensembleAutoStart).zookeeperPassword(decodedZookeeperPassword).zooKeeperServerPort(zookeeperServerPort).zooKeeperServerConnectionPort(zookeeperServerConnectionPort).autoImportEnabled(profilesAutoImport).importPath(profilesAutoImportPath).resolver(localResolver).globalResolver(globalResolver).users(userProps).minimumPort(minport).maximumPort(maxport).profiles(profiles).version(version).build();
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) IOException(java.io.IOException) RuntimeProperties(io.fabric8.api.RuntimeProperties) Properties(org.apache.felix.utils.properties.Properties) File(java.io.File)

Example 38 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by jboss-fuse.

the class ZooKeeperServerFactory method activateInternal.

private Destroyable activateInternal(BundleContext context, Map<String, ?> configuration) throws Exception {
    LOGGER.info("Creating zookeeper server with: {}", configuration);
    Properties props = new Properties();
    for (Entry<String, ?> entry : configuration.entrySet()) {
        props.put(entry.getKey(), entry.getValue());
    }
    // Remove the dependency on the current dir from dataDir
    String dataDir = props.getProperty("dataDir");
    if (dataDir != null && !Paths.get(dataDir).isAbsolute()) {
        dataDir = runtimeProperties.get().getDataPath().resolve(dataDir).toFile().getAbsolutePath();
        props.setProperty("dataDir", dataDir);
    }
    props.put("clientPortAddress", bootstrapConfiguration.get().getBindAddress());
    // Create myid file
    String serverId = (String) props.get("server.id");
    if (serverId != null) {
        props.remove("server.id");
        File myId = new File(dataDir, "myid");
        if (myId.exists() && !myId.delete()) {
            throw new IOException("Failed to delete " + myId);
        }
        if (myId.getParentFile() == null || (!myId.getParentFile().exists() && !myId.getParentFile().mkdirs())) {
            throw new IOException("Failed to create " + myId.getParent());
        }
        FileOutputStream fos = new FileOutputStream(myId);
        try {
            fos.write((serverId + "\n").getBytes());
        } finally {
            fos.close();
        }
    }
    QuorumPeerConfig peerConfig = getPeerConfig(props);
    if (!peerConfig.getServers().isEmpty()) {
        NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
        cnxnFactory.configure(peerConfig.getClientPortAddress(), peerConfig.getMaxClientCnxns());
        QuorumPeer quorumPeer = new QuorumPeer();
        quorumPeer.setClientPortAddress(peerConfig.getClientPortAddress());
        quorumPeer.setTxnFactory(new FileTxnSnapLog(new File(peerConfig.getDataLogDir()), new File(peerConfig.getDataDir())));
        quorumPeer.setQuorumPeers(peerConfig.getServers());
        quorumPeer.setElectionType(peerConfig.getElectionAlg());
        quorumPeer.setMyid(peerConfig.getServerId());
        quorumPeer.setTickTime(peerConfig.getTickTime());
        quorumPeer.setMinSessionTimeout(peerConfig.getMinSessionTimeout());
        quorumPeer.setMaxSessionTimeout(peerConfig.getMaxSessionTimeout());
        quorumPeer.setInitLimit(peerConfig.getInitLimit());
        quorumPeer.setSyncLimit(peerConfig.getSyncLimit());
        quorumPeer.setQuorumVerifier(peerConfig.getQuorumVerifier());
        quorumPeer.setCnxnFactory(cnxnFactory);
        quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
        quorumPeer.setLearnerType(peerConfig.getPeerType());
        try {
            LOGGER.debug("Starting quorum peer \"{}\" on address {}", quorumPeer.getMyid(), peerConfig.getClientPortAddress());
            quorumPeer.start();
            LOGGER.debug("Started quorum peer \"{}\"", quorumPeer.getMyid());
        } catch (Exception e) {
            LOGGER.warn("Failed to start quorum peer \"{}\", reason : {} ", quorumPeer.getMyid(), e.getMessage());
            quorumPeer.shutdown();
            throw e;
        }
        // Register stats provider
        ClusteredServer server = new ClusteredServer(quorumPeer);
        registration = context.registerService(QuorumStats.Provider.class, server, null);
        return server;
    } else {
        ServerConfig serverConfig = getServerConfig(peerConfig);
        ZooKeeperServer zkServer = new ZooKeeperServer();
        FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(serverConfig.getDataLogDir()), new File(serverConfig.getDataDir()));
        zkServer.setTxnLogFactory(ftxn);
        zkServer.setTickTime(serverConfig.getTickTime());
        zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());
        NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory() {

            protected void configureSaslLogin() throws IOException {
            }
        };
        cnxnFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
        try {
            LOGGER.debug("Starting ZooKeeper server on address {}", peerConfig.getClientPortAddress());
            cnxnFactory.startup(zkServer);
            LOGGER.debug("Started ZooKeeper server");
        } catch (Exception e) {
            LOGGER.warn("Failed to start ZooKeeper server, reason : {}", e);
            cnxnFactory.shutdown();
            throw e;
        }
        // Register stats provider
        SimpleServer server = new SimpleServer(zkServer, cnxnFactory);
        registration = context.registerService(ServerStats.Provider.class, server, null);
        startCleanupManager(serverConfig, props);
        return server;
    }
}
Also used : IOException(java.io.IOException) RuntimeProperties(io.fabric8.api.RuntimeProperties) Properties(java.util.Properties) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IOException(java.io.IOException) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) FileOutputStream(java.io.FileOutputStream) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer) File(java.io.File)

Example 39 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by jboss-fuse.

the class ProxyServlet method init.

/**
 * Initialize the <code>ProxyServlet</code>
 *
 * @param config The Servlet configuration passed in by the servlet container
 */
@Override
public void init(ServletConfig config) throws ServletException {
    HttpProxyRuleBase ruleBase = new HttpProxyRuleBase();
    loadRuleBase(config, ruleBase);
    resolver.setMappingRules(ruleBase);
    Protocol.registerProtocol("http", new Protocol("http", new NonBindingSocketFactory(), 80));
    Protocol.registerProtocol("https", new Protocol("https", new NonBindingSocketFactory(), 443));
}
Also used : HttpProxyRuleBase(io.fabric8.gateway.model.HttpProxyRuleBase) Protocol(org.apache.commons.httpclient.protocol.Protocol) NonBindingSocketFactory(io.fabric8.gateway.servlet.support.NonBindingSocketFactory)

Example 40 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by jboss-fuse.

the class FabricCreateCommandTest method testLocalFabricCluster.

@Test
public void testLocalFabricCluster() throws Exception {
    CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
    FabricService fabricService = ServiceLocator.getRequiredService(FabricService.class);
    Container[] containers = fabricService.getContainers();
    Assert.assertNotNull("Containers not null", containers);
    // Test that a provided default password exists
    ConfigurationAdmin configurationAdmin = ServiceLocator.getRequiredService(ConfigurationAdmin.class);
    org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration(io.fabric8.api.Constants.ZOOKEEPER_CLIENT_PID);
    Dictionary<String, Object> dictionary = configuration.getProperties();
    Assert.assertEquals("Expected provided zookeeper password", PasswordEncoder.encode(ADMIN_PASSWORD), dictionary.get("zookeeper.password"));
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)29 HashMap (java.util.HashMap)23 File (java.io.File)22 Configuration (org.osgi.service.cm.Configuration)20 Map (java.util.Map)16 BootstrapConfiguration (io.fabric8.zookeeper.bootstrap.BootstrapConfiguration)15 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 Container (io.fabric8.api.Container)11 Profile (io.fabric8.api.Profile)11 RuntimeProperties (io.fabric8.api.RuntimeProperties)9 HashSet (java.util.HashSet)9 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 FabricException (io.fabric8.api.FabricException)7 FabricService (io.fabric8.api.FabricService)7 Properties (java.util.Properties)7 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)6 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)5 URL (java.net.URL)5