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);
}
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();
}
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;
}
}
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));
}
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"));
}
Aggregations