/** * @param configuration Object carrying all configurable properties from file. * @throws UnRetriableException * @link configure method supplies the configuration object carrying all the properties parsed * from the external properties file. */ public void configure(Configuration configuration) throws UnRetriableException { log.info(" configure : setting up our configurations."); int tcpPort = configuration.getInt( CONFIGURATION_SERVER_MQTT_TCP_PORT, CONFIGURATION_VALUE_DEFAULT_SERVER_MQTT_TCP_PORT); setTcpPort(tcpPort); int sslPort = configuration.getInt( CONFIGURATION_SERVER_MQTT_SSL_PORT, CONFIGURATION_VALUE_DEFAULT_SERVER_MQTT_SSL_PORT); setSslPort(sslPort); boolean sslEnabled = configuration.getBoolean( CONFIGURATION_SERVER_MQTT_SSL_IS_ENABLED, CONFIGURATION_VALUE_DEFAULT_SERVER_MQTT_SSL_IS_ENABLED); setSslEnabled(sslEnabled); if (isSslEnabled()) { setSslHandler(new SSLHandler(configuration)); } int connectionTimeout = configuration.getInt( CONFIGURATION_SERVER_MQTT_CONNECTION_TIMEOUT, CONFIGURATION_VALUE_DEFAULT_SERVER_MQTT_CONNECTION_TIMEOUT); setConnectionTimeout(connectionTimeout); }
public Backend(Configuration storageConfig) { this.storageConfig = storageConfig; storeManager = getStorageManager(storageConfig); indexes = getIndexes(storageConfig); storeFeatures = storeManager.getFeatures(); basicMetrics = storageConfig.getBoolean(BASIC_METRICS, BASIC_METRICS_DEFAULT); mergeBasicMetrics = storageConfig.getBoolean(MERGE_BASIC_METRICS_KEY, MERGE_BASIC_METRICS_DEFAULT); int bufferSizeTmp = storageConfig.getInt(BUFFER_SIZE_KEY, BUFFER_SIZE_DEFAULT); Preconditions.checkArgument( bufferSizeTmp >= 0, "Buffer size must be non-negative (use 0 to disable)"); if (!storeFeatures.supportsBatchMutation()) { bufferSize = 0; log.debug("Buffering disabled because backend does not support batch mutations"); } else bufferSize = bufferSizeTmp; writeAttempts = storageConfig.getInt(WRITE_ATTEMPTS_KEY, WRITE_ATTEMPTS_DEFAULT); Preconditions.checkArgument(writeAttempts > 0, "Write attempts must be positive"); readAttempts = storageConfig.getInt(READ_ATTEMPTS_KEY, READ_ATTEMPTS_DEFAULT); Preconditions.checkArgument(readAttempts > 0, "Read attempts must be positive"); persistAttemptWaittime = storageConfig.getInt(STORAGE_ATTEMPT_WAITTIME_KEY, STORAGE_ATTEMPT_WAITTIME_DEFAULT); Preconditions.checkArgument( persistAttemptWaittime > 0, "Persistence attempt retry wait time must be non-negative"); // If lock prefix is unspecified, specify it now storageConfig.setProperty( ExpectedValueCheckingStore.LOCAL_LOCK_MEDIATOR_PREFIX_KEY, storageConfig.getString( ExpectedValueCheckingStore.LOCAL_LOCK_MEDIATOR_PREFIX_KEY, storeManager.getName())); final String lockBackendName = storageConfig.getString( GraphDatabaseConfiguration.LOCK_BACKEND, GraphDatabaseConfiguration.LOCK_BACKEND_DEFAULT); if (REGISTERED_LOCKERS.containsKey(lockBackendName)) { lockerCreator = REGISTERED_LOCKERS.get(lockBackendName); } else { throw new TitanConfigurationException( "Unknown lock backend \"" + lockBackendName + "\". Known lock backends: " + Joiner.on(", ").join(REGISTERED_LOCKERS.keySet()) + "."); } // Never used for backends that have innate transaction support, but we // want to maintain the non-null invariant regardless; it will default // to connsistentkey impl if none is specified Preconditions.checkNotNull(lockerCreator); if (storeFeatures.isDistributed() && storeFeatures.isKeyOrdered()) { log.debug("Wrapping index store with HashPrefix"); hashPrefixIndex = true; } else { hashPrefixIndex = false; } }
@Override public void configurate(Configuration configuration, ConfigurableBuilder builder) throws BuildException { this.hostname = configuration.getString(HOSTNAME); this.port = configuration.getInt(PORT); this.workerHostname = configuration.getString(WORKER_HOSTNAME); this.workerPort = configuration.getInt(WORKER_PORT); }
private static int getPortValue(Configuration configuration, String enableTLSFlag) { int appPort; assert configuration != null; appPort = StringUtils.isEmpty(enableTLSFlag) || enableTLSFlag.equals("true") ? configuration.getInt(ATLAS_SERVER_HTTPS_PORT, 21443) : configuration.getInt(ATLAS_SERVER_HTTP_PORT, 21000); return appPort; }
private static NetworkServer buildNetworkServer(Configuration conf, ClusterClient clusterClient) { NetworkServerConfig networkConfig = new NetworkServerConfig(); networkConfig.setClusterClient(clusterClient); networkConfig.setRequestThreadCorePoolSize(conf.getInt(SERVER_REQ_THREAD_POOL_SIZE, 20)); networkConfig.setRequestThreadMaxPoolSize(conf.getInt(SERVER_REQ_THREAD_POOL_MAXSIZE, 70)); networkConfig.setRequestThreadKeepAliveTimeSecs( conf.getInt(SERVER_REQ_THREAD_POOL_KEEPALIVE, 300)); return new NettyNetworkServer(networkConfig); }
/** * Configuration method. * * <p>Configuration parameters for PrefExprIndividualSpecies are: * * <ul> * </ul> */ @SuppressWarnings("unchecked") public void configure(Configuration settings) { // Header String header = "expression-tree"; // Get minimum-tree-size int minTreeSize = settings.getInt(header + ".min-tree-size"); setMinTreeSize(minTreeSize); // Get minimum-tree-size int maxTreeSize = settings.getInt(header + ".max-tree-size"); setMaxTreeSize(maxTreeSize); // Get root type String rootTypeName = settings.getString(header + ".root-type"); try { Class<?> rootType = Class.forName(rootTypeName); setRootType(rootType); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException(""); } // Get terminals set int numberOfTerminals = settings.getList(header + ".terminals.terminal[@class]").size(); IPrimitive[] terminals = new IPrimitive[numberOfTerminals]; for (int j = 0; j < numberOfTerminals; j++) { try { String terminalClassname = settings.getString(header + ".terminals.terminal(" + j + ")[@class]"); Class<IPrimitive> terminalClass = (Class<IPrimitive>) Class.forName(terminalClassname); terminals[j] = terminalClass.newInstance(); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException(); } catch (InstantiationException e) { throw new ConfigurationRuntimeException(); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException(); } } setTerminals(terminals); // Get functions set int numberOfFunctions = settings.getList(header + ".functions.function[@class]").size(); IPrimitive[] functions = new IPrimitive[numberOfFunctions]; for (int j = 0; j < numberOfFunctions; j++) { try { String functionClassname = settings.getString(header + ".functions.function(" + j + ")[@class]"); Class<IPrimitive> functionClass = (Class<IPrimitive>) Class.forName(functionClassname); functions[j] = functionClass.newInstance(); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException(); } catch (InstantiationException e) { throw new ConfigurationRuntimeException(); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException(); } } setFunctions(functions); }
public ZooKeeperBenchmark(Configuration conf) throws IOException { LinkedList<String> serverList = new LinkedList<String>(); Iterator<String> serverNames = conf.getKeys("server"); while (serverNames.hasNext()) { String serverName = serverNames.next(); String address = conf.getString(serverName); serverList.add(address); } if (serverList.size() == 0) { throw new IllegalArgumentException("ZooKeeper server addresses required"); } _interval = conf.getInt("interval"); _totalOps = conf.getInt("totalOperations"); _lowerbound = conf.getInt("lowerbound"); int totaltime = conf.getInt("totalTime"); _totalTimeSeconds = Math.round((double) totaltime / 1000.0); boolean sync = conf.getBoolean("sync"); _running = new HashMap<Integer, Thread>(); _clients = new BenchmarkClient[serverList.size()]; _barrier = new CyclicBarrier(_clients.length + 1); _deadline = totaltime / _interval; LOG.info( "benchmark set with: interval: " + _interval + " total number: " + _totalOps + " threshold: " + _lowerbound + " time: " + totaltime + " sync: " + (sync ? "SYNC" : "ASYNC")); _data = ""; for (int i = 0; i < 20; i++) { // 100 bytes of important data _data += "!!!!!"; } int avgOps = _totalOps / serverList.size(); for (int i = 0; i < serverList.size(); i++) { if (sync) { _clients[i] = new SyncBenchmarkClient(this, serverList.get(i), "/zkTest", avgOps, i); } else { _clients[i] = new AsyncBenchmarkClient(this, serverList.get(i), "/zkTest", avgOps, i); } } }
@Override public void updateConfiguration(final Configuration config, final int hint) { /** Can be extended. */ if (config == null) { return; } if (ConfigHint.NATIVE_FILE == hint || ConfigHint.CLI_OVERRIDE == hint) { setPushToProcessSize( config.getInt(PollingKey.pushToProcessSize.toString(), pushToProcessSize)); setPushToProcessMilli( config.getInt(PollingKey.pushToProcessMilli.toString(), getPushToProcessMilli())); } }
public boolean startServer() { context.starting(); Configuration configuration = getContext().getService(Configuration.class); int port = configuration.getInt(ServerConfiguration.PORT); try { context.getServer().setCharset("ISO-8859-1"); // open a non-blocking server socket channel sSockChan = ServerSocketChannel.open(); sSockChan.configureBlocking(false); // bind to localhost on designated port // ***InetAddress addr = InetAddress.getLocalHost(); // ***sSockChan.socket().bind(new InetSocketAddress(addr, port)); sSockChan.socket().bind(new InetSocketAddress(port)); // get a selector for multiplexing the client channels readSelector = Selector.open(); } catch (IOException ex) { LOG.error("Could not listen on port: " + port, ex); return false; } LOG.info("Listening for connections on TCP port {} ...", port); context.started(); return true; }
@Override public void started() { // As DateFormats are generally not-thread save, // we always create a new one. DateFormat dateTimeFormat = new SimpleDateFormat("yyyy.MM.dd 'at' hh:mm:ss z"); LOG.info( "{} {} started on {}", new Object[] { Server.getApplicationName(), Misc.getAppVersionNonNull(), dateTimeFormat.format(new Date()) }); // add server notification ServerNotification sn = new ServerNotification("Server started"); Configuration conf = getContext().getService(Configuration.class); int port = conf.getInt(ServerConfiguration.PORT); sn.addLine( String.format( "Server has been started on port %d." + " There are %d accounts. " + "See server log for more info.", port, context.getAccountsService().getAccountsSize())); context.getServerNotifications().addNotification(sn); createAdminIfNoUsers(); }
public static void main(String[] args) throws IOException, TException { OptionParser parser = new OptionParser(); parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class); parser.accepts("help", "print help statement"); OptionSet options = parser.parse(args); if (options.has("help")) { parser.printHelpOn(System.out); System.exit(-1); } // Logger configuration: log to the console BasicConfigurator.configure(); LOG.setLevel(Level.DEBUG); LOG.debug("debug logging on"); Configuration conf = new PropertiesConfiguration(); if (options.has("c")) { String configFile = (String) options.valueOf("c"); try { conf = new PropertiesConfiguration(configFile); } catch (ConfigurationException e) { } } // Start backend server BackendService.Processor<BackendService.Iface> processor = new BackendService.Processor<BackendService.Iface>(new ProtoBackend()); int listenPort = conf.getInt("listen_port", DEFAULT_LISTEN_PORT); NM_PORT = conf.getInt("node_monitor_port", NodeMonitorThrift.DEFAULT_NM_THRIFT_PORT); TServers.launchThreadedThriftServer(listenPort, THRIFT_WORKER_THREADS, processor); // Register server client = TClients.createBlockingNmClient(NM_HOST, NM_PORT); try { client.registerBackend(APP_ID, "localhost:" + listenPort); LOG.debug("Client successfullly registered"); } catch (TTransportException e) { LOG.debug("Error while registering backend: " + e.getMessage()); } }
/** * @return Connection from the connection pool. Clients must <code>close()</code> it when they are * done with it. * @throws SQLException */ public static synchronized Connection getConnection() throws SQLException { if (dataSource == null) { final Configuration config = Application.getConfiguration(); final String connectionString = config.getString(JDBC_URL_CONFIG_KEY, ""); final int connectionTimeout = 1000 * config.getInt(CONNECTION_TIMEOUT_CONFIG_KEY, 10); final int maxPoolSize = config.getInt(MAX_POOL_SIZE_CONFIG_KEY, 10); final String user = config.getString(USER_CONFIG_KEY, ""); final String password = config.getString(PASSWORD_CONFIG_KEY, ""); dataSource = new HikariDataSource(); dataSource.setJdbcUrl(connectionString); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setPoolName("JdbcResolverPool"); dataSource.setMaximumPoolSize(maxPoolSize); dataSource.setConnectionTimeout(connectionTimeout); } return dataSource.getConnection(); }
@Override public void run() { try { Thread.sleep(3000); String uberdustServerDnsName = config.getString("uberdustcoapserver.dnsName"); if (uberdustServerDnsName == null) { throw new Exception("Property uberdustcoapserver.dnsName not set."); } int uberdustServerPort = config.getInt("uberdustcoapserver.port", 0); if (uberdustServerPort == 0) { throw new Exception("Property uberdustcoapserver.port not set."); } InetSocketAddress uberdustServerSocketAddress = new InetSocketAddress(InetAddress.getByName(uberdustServerDnsName), uberdustServerPort); String baseURI = config.getString("baseURIHost", "localhost"); CoapRequest fakeRequest = new CoapRequest( MsgType.NON, Code.POST, new URI("coap://" + baseURI + ":5683/here_i_am")); CoapNodeRegistrationServer registrationServer = CoapNodeRegistrationServer.getInstance(); if (registrationServer == null) { log.error("NULL!"); } registrationServer.receiveCoapRequest(fakeRequest, uberdustServerSocketAddress); } catch (InterruptedException e) { e.printStackTrace(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (URISyntaxException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (InvalidMessageException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (InvalidOptionException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (ToManyOptionsException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (Exception e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }
@Override public void exec(Configuration configuration) throws Exception { String hostname = configuration.getString(HOSTNAME); int port = configuration.getInt(PORT); String workerHostname = configuration.getString(WORKER_HOSTNAME); int workerPort = configuration.getInt(WORKER_PORT); RemoteMessageSender sender = new RemoteMessageSender(); QueueService service = new QueueService(hostname, port); FDListener listener = new FDStatusListener(service); FDClientActor actor = new FDClientActor(5, 1, TimeUnit.SECONDS, listener, sender); ServiceID workerID = ServiceIDUtils.toResolvedServiceID(workerHostname, workerPort, FDServerActor.HANDLE); actor.withSimpleQueue(service).startProcessors(1); actor.startTimer(); actor.watch(workerID, true); }
private void loadProperties(String propsPath) throws ConfigurationException, UnknownHostException { Configuration props = new PropertiesConfiguration(propsPath); sourceHost = props.getString("sourceHost"); sourcePort = props.getInt("sourcePort"); sourceDatabaseName = props.getString("sourceDatabase"); sourceCollectionName = props.getString("sourceCollection"); if (sourceHost == null || sourcePort == null || sourceDatabaseName == null || sourceCollectionName == null) { throw new ConfigurationException( "Missing configuration: sourceHost, sourcePort, sourceDatabase, and sourceCollection are required"); } sourceMongoClient = new MongoClient(sourceHost, sourcePort); sourceDb = sourceMongoClient.getDB(sourceDatabaseName); sourceCollection = sourceDb.getCollection(sourceCollectionName); destinationHost = props.getString("destinationHost", sourceHost); destinationPort = props.getInt("destinationPort", sourcePort); destinationDatabaseName = props.getString("destinationDatabase", sourceDatabaseName); destinationCollectionName = props.getString("destinationCollection", sourceCollectionName); destinationMongoClient = new MongoClient(destinationHost, destinationPort); destinationDb = sourceMongoClient.getDB(destinationDatabaseName); destinationCollection = sourceDb.getCollection(destinationCollectionName); if (props.getString("sourceQuery") != null) { sourceQuery = (DBObject) JSON.parse(props.getString("sourceQuery")); } // if (props.getString("sourceProjection") != null) { sourceProjection = (DBObject) JSON.parse(props.getString("sourceProjection", DEFAULT_PROJECTION)); // } setQueueSize(props.getInt("queueSize", 1000000)); setThreads(props.getInt("threads", 8)); }
public Backend(Configuration storageConfig) { storeManager = getStorageManager(storageConfig); isKeyColumnValueStore = storeManager instanceof KeyColumnValueStoreManager; storeFeatures = storeManager.getFeatures(); int bufferSizeTmp = storageConfig.getInt(BUFFER_SIZE_KEY, BUFFER_SIZE_DEFAULT); Preconditions.checkArgument( bufferSizeTmp >= 0, "Buffer size must be non-negative (use 0 to disable)"); if (!storeFeatures.supportsBatchMutation()) { bufferSize = 0; log.debug("Buffering disabled because backend does not support batch mutations"); } else bufferSize = bufferSizeTmp; if (!storeFeatures.supportsLocking() && storeFeatures.supportsConsistentKeyOperations()) { lockConfiguration = new ConsistentKeyLockConfiguration(storageConfig, storeManager.toString()); } else { lockConfiguration = null; } writeAttempts = storageConfig.getInt(WRITE_ATTEMPTS_KEY, WRITE_ATTEMPTS_DEFAULT); Preconditions.checkArgument(writeAttempts > 0, "Write attempts must be positive"); readAttempts = storageConfig.getInt(READ_ATTEMPTS_KEY, READ_ATTEMPTS_DEFAULT); Preconditions.checkArgument(readAttempts > 0, "Read attempts must be positive"); persistAttemptWaittime = storageConfig.getInt(STORAGE_ATTEMPT_WAITTIME_KEY, STORAGE_ATTEMPT_WAITTIME_DEFAULT); Preconditions.checkArgument( persistAttemptWaittime > 0, "Persistence attempt retry wait time must be non-negative"); if (storeFeatures.isDistributed() && storeFeatures.isKeyOrdered()) { log.debug("Wrapping index store with HashPrefix"); hashPrefixIndex = true; } else { hashPrefixIndex = false; } }
public ClusterClient buildClusterClient() { String clusterName = _senseiConf.getString(SENSEI_CLUSTER_NAME); String clusterClientName = _senseiConf.getString(SENSEI_CLUSTER_CLIENT_NAME, clusterName); String zkUrl = _senseiConf.getString(SENSEI_CLUSTER_URL); int zkTimeout = _senseiConf.getInt(SENSEI_CLUSTER_TIMEOUT, 300000); ClusterClient clusterClient = new ZooKeeperClusterClient(clusterClientName, clusterName, zkUrl, zkTimeout); logger.info("Connecting to cluster: " + clusterName + " ..."); clusterClient.awaitConnectionUninterruptibly(); logger.info("Cluster: " + clusterName + " successfully connected "); return clusterClient; }
/** * Configuration method. * * <p>Configuration parameters for BaseAlgorithm class are: * * <ul> * <li><code>species: ISpecies (complex)</code> Individual species * <li><code>evaluator: IEvaluator (complex)</code> Individuals evaluator * <li><code>population-size: int</code> Population size * <li><code>max-of-generations: int</code> Maximum number of generations * <li><code>provider: IProvider (complex)</code> Individuals provider * <li><code>mu: int</code> Number of parents to select * <li><code>lambda: int</code> Number of son to obtain by recombination * <li><code>recombinator: IRecombinator (complex)</code> Recombination operator * </ul> */ @SuppressWarnings("unchecked") public void configure(Configuration configuration) { // Call super.configure() method super.configure(configuration); // Mu parameter int mu = configuration.getInt("mu"); setMu(mu); // Lambda parameter int lambda = configuration.getInt("lambda"); setLambda(lambda); // Recombinator try { // Recombinator classname String recombinatorClassname = configuration.getString("recombinator[@type]"); // Recombinator class Class<? extends IRecombinator> recombinatorClass = (Class<? extends IRecombinator>) Class.forName(recombinatorClassname); // Recombinator instance IRecombinator recombinator = recombinatorClass.newInstance(); // Configure recombinator if necessary if (recombinator instanceof IConfigure) { // Extract recombinator configuration Configuration recombinatorConfiguration = configuration.subset("recombinator"); // Configure species ((IConfigure) recombinator).configure(recombinatorConfiguration); } // Set species setRecombinator(recombinator); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal recombinator classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of recombinator", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of recombinator", e); } }
public AstyanaxStoreManager(Configuration config) throws StorageException { super(config); // Check if we have non-default thrift frame size or max message size set and warn users // because there is nothing we can do in Astyanax to apply those, warning is good enough here // otherwise it would make bad user experience if we don't warn at all or crash on this. if (this.thriftFrameSize != THRIFT_DEFAULT_FRAME_SIZE) log.warn("Couldn't set custom Thrift Frame Size property, use 'cassandrathrift' instead."); if (this.thriftMaxMessageSize != THRIFT_DEFAULT_MAX_MESSAGE_SIZE) log.warn( "Couldn't set custom Thrift Max Message Size property, use 'cassandrathrift' instead."); this.clusterName = config.getString(CLUSTER_KEY, CLUSTER_DEFAULT); this.retryPolicy = getRetryPolicy(config.getString(RETRY_POLICY_KEY, RETRY_POLICY_DEFAULT)); final int maxConnsPerHost = config.getInt(MAX_CONNECTIONS_PER_HOST_KEY, MAX_CONNECTIONS_PER_HOST_DEFAULT); final int maxClusterConnsPerHost = config.getInt( MAX_CLUSTER_CONNECTIONS_PER_HOST_KEY, MAX_CLUSTER_CONNECTIONS_PER_HOST_DEFAULT); this.clusterContext = createCluster(getContextBuilder(config, maxClusterConnsPerHost, "Cluster")); ensureKeyspaceExists(clusterContext.getEntity()); this.keyspaceContext = getContextBuilder(config, maxConnsPerHost, "Keyspace") .buildKeyspace(ThriftFamilyFactory.getInstance()); this.keyspaceContext.start(); openStores = new HashMap<String, AstyanaxOrderedKeyColumnValueStore>(8); }
public URI createHttpMirrorURI(InetAddress remoteAddress, String path) throws URISyntaxException { String uberdustServerDns = config.getString("uberdustcoapserver.dnsName", remoteAddress.getHostAddress()); String sspHostname = ""; int sspPort; try { sspHostname = config.getString("baseURIHost", InetAddress.getLocalHost().getHostAddress()); } catch (UnknownHostException e) { log.error(e); } sspPort = config.getInt("listenPort"); return new URI("http://" + sspHostname + ":" + sspPort + "/" + uberdustServerDns + path + "#"); }
public SenseiServer buildServer() throws ConfigurationException { int port = _senseiConf.getInt(SERVER_PORT); JmxSenseiMBeanServer.registerCustomMBeanServer(); ClusterClient clusterClient = buildClusterClient(); NetworkServer networkServer = buildNetworkServer(_senseiConf, clusterClient); SenseiCore core = buildCore(); List<AbstractSenseiCoreService<AbstractSenseiRequest, AbstractSenseiResult>> svcList = (List) pluginRegistry.resolveBeansByListKey( SENSEI_PLUGIN_SVCS, AbstractSenseiCoreService.class); return new SenseiServer(port, networkServer, clusterClient, core, svcList, pluginRegistry); }
@Override public void execute(CommandLineArguments arguments) { logger.info("AddNodesCommand local execute."); if (isArgumentsCountFalse(arguments)) { return; } Scanner scanner = arguments.asScanner(); int numberOfNodes = scanner.nextInt(); int numberOfCpusPerNode = scanner.nextInt(); final Configuration configuration = getNodeManager().getConfiguration(); Collection<File> artifactsToPreload = DependencyConfigurationUtil.getConfiguredDependencies(configuration); String jvmOptions = configuration.getString( ConfigurationKeys.JVM_OPTIONS_NODE, ConfigurationKeys.DEFAULT_JVM_OPTIONS_NODE); String nodeLogLevel = configuration.getString( ConfigurationKeys.LOGGING_NODE_LEVEL, ConfigurationKeys.DEFAULT_LOGGING_NODE_LEVEL); boolean nodeRemoteLogging = configuration.getBoolean( ConfigurationKeys.LOGGING_NODE_REMOTE, ConfigurationKeys.DEFAULT_LOGGING_NODE_REMOTE); int nodeRemoteLoggingPort = configuration.getInt( ConfigurationKeys.LOGGING_NODE_REMOTE_PORT, ConfigurationKeys.DEFAULT_LOGGING_NODE_REMOTE_PORT); final LocalNodeConfiguration nodeConfiguration = LocalNodeConfiguration.configurationFor( artifactsToPreload, jvmOptions, nodeLogLevel, nodeRemoteLogging, nodeRemoteLoggingPort, numberOfCpusPerNode); for (int i = 0; i < numberOfNodes; i++) { getNodeManager().addNode(nodeConfiguration); } }
@Override public void configure(Configuration conf) { if (conf.containsKey("MaxNumRestarts")) { this.max_num_restarts = conf.getInt("MaxNumRestarts"); } else { ConfWarning w = new ConfWarning( this.getClass().getSimpleName() + ".MaxNumRestarts", this.max_num_restarts); w.warn(); } if (conf.containsKey("IncrPopFactor")) { this.incr_factor = conf.getDouble("IncrPopFactor"); } else { ConfWarning w = new ConfWarning(this.getClass().getSimpleName() + ".IncrPopFactor", this.incr_factor); w.warn(); } }
/** * <code>configure</code> allows the base system to configure itself by getting all the settings * it requires and storing them internally. The plugin is only expected to pick the settings it * has registered on the configuration file for its particular use. * * @param configuration * @throws UnRetriableException */ @Override public void configure(Configuration configuration) throws UnRetriableException { boolean configAnnoymousLoginEnabled = configuration.getBoolean( CORE_CONFIG_WORKER_ANNONYMOUS_LOGIN_ENABLED, CORE_CONFIG_WORKER_ANNONYMOUS_LOGIN_ENABLED_DEFAULT_VALUE); log.debug( " configure : Anonnymous login is configured to be enabled [{}]", configAnnoymousLoginEnabled); setAnnonymousLoginEnabled(configAnnoymousLoginEnabled); String configAnnoymousLoginUsername = configuration.getString( CORE_CONFIG_WORKER_ANNONYMOUS_LOGIN_USERNAME, CORE_CONFIG_ENGINE_WORKER_ANNONYMOUS_LOGIN_USERNAME_DEFAULT_VALUE); log.debug( " configure : Anonnymous login username is configured to be [{}]", configAnnoymousLoginUsername); setAnnonymousLoginUsername(configAnnoymousLoginUsername); String configAnnoymousLoginPassword = configuration.getString( CORE_CONFIG_WORKER_ANNONYMOUS_LOGIN_PASSWORD, CORE_CONFIG_ENGINE_WORKER_ANNONYMOUS_LOGIN_PASSWORD_DEFAULT_VALUE); log.debug( " configure : Anonnymous login password is configured to be [{}]", configAnnoymousLoginPassword); setAnnonymousLoginPassword(configAnnoymousLoginPassword); int keepaliveInSeconds = configuration.getInt( CORE_CONFIG_WORKER_CLIENT_KEEP_ALIVE_IN_SECONDS, CORE_CONFIG_WORKER_CLIENT_KEEP_ALIVE_IN_SECONDS_DEFAULT_VALUE); log.debug(" configure : Keep alive maximum is configured to be [{}]", keepaliveInSeconds); setKeepAliveInSeconds(keepaliveInSeconds); }
public HelixBrokerStarter( String helixClusterName, String zkServer, Configuration pinotHelixProperties) throws Exception { _liveInstancesListener = new LiveInstancesChangeListenerImpl(helixClusterName); _pinotHelixProperties = DefaultHelixBrokerConfig.getDefaultBrokerConf(pinotHelixProperties); final String brokerId = _pinotHelixProperties.getString( "instanceId", CommonConstants.Helix.PREFIX_OF_BROKER_INSTANCE + NetUtil.getHostAddress() + "_" + _pinotHelixProperties.getInt( CommonConstants.Helix.KEY_OF_BROKER_QUERY_PORT, CommonConstants.Helix.DEFAULT_BROKER_QUERY_PORT)); _pinotHelixProperties.addProperty("pinot.broker.id", brokerId); RoutingTableBuilder defaultOfflineRoutingTableBuilder = getRoutingTableBuilder( _pinotHelixProperties.subset(DEFAULT_OFFLINE_ROUTING_TABLE_BUILDER_KEY)); RoutingTableBuilder defaultRealtimeRoutingTableBuilder = getRoutingTableBuilder( _pinotHelixProperties.subset(DEFAULT_REALTIME_ROUTING_TABLE_BUILDER_KEY)); Map<String, RoutingTableBuilder> tableToRoutingTableBuilderMap = getTableToRoutingTableBuilderMap(_pinotHelixProperties.subset(ROUTING_TABLE_BUILDER_KEY)); ZkClient zkClient = new ZkClient( StringUtil.join( "/", StringUtils.chomp(zkServer, "/"), helixClusterName, "PROPERTYSTORE"), ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); _propertyStore = new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(zkClient), "/", null); _helixExternalViewBasedRouting = new HelixExternalViewBasedRouting( defaultOfflineRoutingTableBuilder, defaultRealtimeRoutingTableBuilder, tableToRoutingTableBuilderMap, _propertyStore); // _brokerServerBuilder = startBroker(); _brokerServerBuilder = startBroker(_pinotHelixProperties); _helixManager = HelixManagerFactory.getZKHelixManager( helixClusterName, brokerId, InstanceType.PARTICIPANT, zkServer); final StateMachineEngine stateMachineEngine = _helixManager.getStateMachineEngine(); final StateModelFactory<?> stateModelFactory = new BrokerResourceOnlineOfflineStateModelFactory( _helixManager, _helixExternalViewBasedRouting); stateMachineEngine.registerStateModelFactory( BrokerResourceOnlineOfflineStateModelFactory.getStateModelDef(), stateModelFactory); _helixManager.connect(); _helixAdmin = _helixManager.getClusterManagmentTool(); _helixBrokerRoutingTable = new HelixBrokerRoutingTable(_helixExternalViewBasedRouting, brokerId, _helixManager); addInstanceTagIfNeeded(helixClusterName, brokerId); _helixManager.addExternalViewChangeListener(_helixBrokerRoutingTable); _helixManager.addInstanceConfigChangeListener(_helixBrokerRoutingTable); _helixManager.addLiveInstanceChangeListener(_liveInstancesListener); }
/** @return the elasticsearch port */ public int getStorageESPort() { return config.getInt(APIMAN_MANAGER_STORAGE_ES_PORT, 19200); }
/** @return the elasticsearch port */ public int getMetricsESPort() { return config.getInt(APIMAN_MANAGER_METRICS_ES_PORT, 19200); }
/** * The EntityManager is the topmost upstream handler of an HTTPEntityMangerPipeline. It contains a * list of {@link eu.spitfire_project.smart_service_proxy.core.Backend}s to manage all available * services behind them. * * @author Henning Hasemann * @author Oliver Kleine */ public class EntityManager extends SimpleChannelHandler { private static Logger log = Logger.getLogger(EntityManager.class.getName()); private static Configuration config; static { try { config = new PropertiesConfiguration("ssp.properties"); } catch (ConfigurationException e) { log.error("Error while loading config.", e); } } public static final String SSP_DNS_NAME = config.getString("SSP_DNS_NAME", "localhost"); public static final int SSP_HTTP_SERVER_PORT = config.getInt("SSP_HTTP_SERVER_PORT", 8080); public static final String DNS_WILDCARD_POSTFIX = config.getString("IPv4_SERVER_DNS_WILDCARD_POSTFIX", null); // Services offered by EntityManager private final String PATH_TO_SERVER_LIST = "/.well-known/servers"; private final String SERVER_PATH_TO_SLSE_UI = "/static/"; private final String LOCAL_PATH_TO_SLSE_UI = "data/slse/ui/create_entity_form.html"; // Parameters for Backend and Entity creation private int nextBackendId = 0; private final String BACKEND_PREFIX_FORMAT = "/be-%04d/"; private int nextEntityId = 0; private final String ENTITY_FORMAT = "/entity-%04x/"; // Contains the URIs of services (e.g. on sensor nodes) and the proper backend private ConcurrentHashMap<URI, Backend> entities = new ConcurrentHashMap<URI, Backend>(); private ConcurrentHashMap<URI, Backend> virtualEntities = new ConcurrentHashMap<URI, Backend>(); // Contains the individual paths to the backends (for Userinterface access) private ConcurrentHashMap<String, Backend> backends = new ConcurrentHashMap<String, Backend>(); private Vector<UIElement> uiElements = new Vector<UIElement>(); // Make EntityManager a Singleton private static EntityManager instance = new EntityManager(); private EntityManager() {} public static EntityManager getInstance() { return instance; } /** */ URI nextEntityURI() { nextEntityId++; return normalizeURI(String.format(ENTITY_FORMAT, nextEntityId)); } /** */ public void registerBackend(Backend backend) { nextBackendId++; String prefix = String.format(BACKEND_PREFIX_FORMAT, nextBackendId); backend.setPrefix(prefix); registerBackend(backend, prefix); } public void registerBackend(Backend backend, String prefix) { if (backends.put(prefix, backend) != backend) { log.debug("New Backend for path prefix " + prefix); } if (backend.getUIElements() != null) { uiElements.addAll(backend.getUIElements()); } } /** * Normalizes the given URI. It removes unnecessary slashes (/) or unnecessary parts of the path * (e.g. /part_1/part_2/../path_3 to /path_1/part_3), removes the # and following characters at * the end of the path and makes relative URIs absolute. * * @param uri The URI to be normalized */ public URI normalizeURI(URI uri) { return normalizeURI(uri.toString()); } /** * Normalizes the given URI. It removes unnecessary slashes (/) or unnecessary parts of the path * (e.g. /part_1/part_2/../path_3 to /path_1/part_3), removes the # and following characters at * the end of the path and makes relative URIs absolute. * * @param uri The URI to be normalized */ public URI normalizeURI(String uri) { while (uri.substring(uri.length() - 1).equals("#")) { uri = uri.substring(0, uri.length() - 1); } URI r = URI.create(SSP_DNS_NAME).resolve(uri).normalize(); return r; } /** * Normalizes the given URI and adds a # at the end. It removes unnecessary slashes (/) or * unnecessary parts of the path (e.g. /part_1/part_2/../path_3 to /path_1/part_3), removes the # * and following characters at the end of the path and makes relative URIs absolute. After * normalizing it adds a # at the end. Example: Both, http://localhost/path/to/service#something * and http://localhost/path/to/service result into http://localhost/path/to/service# * * @param uri The URI to be normalized and converted to represent a thing */ public URI toThing(String uri) { // note: currently we go for the variant without '#' at the end as // that seems to make RDF/XML serializations impossible sometimes return URI.create(normalizeURI(uri).toString() /*+ "#"*/); } /** * Normalizes the given URI and adds a # at the end. It removes unnecessary slashes (/) or * unnecessary parts of the path (e.g. /part_1/part_2/../path_3 to /path_1/part_3), removes the # * and following characters at the end of the path and makes relative URIs absolute. After * normalizing it adds a # at the end. Example: Both, http://localhost/path/to/service#something * and http://localhost/path/to/service result into http://localhost/path/to/service# * * @param uri The URI to be normalized and converted to represent a thing */ public URI toThing(URI uri) { // note: currently we go for the variant without '#' at the end as // that seems to make RDF/XML serializations impossible sometimes return URI.create(normalizeURI(uri).toString() /* + "#"*/); } /** Expected Message types: - HTTP Requests */ @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (!(e.getMessage() instanceof HttpRequest)) { super.messageReceived(ctx, e); return; } HttpRequest httpRequest = (HttpRequest) e.getMessage(); URI targetUri = toThing(URI.create("http://" + httpRequest.getHeader("HOST") + httpRequest.getUri())); log.debug("Received HTTP request for " + targetUri); if (httpRequest.getHeader("HOST").contains(DNS_WILDCARD_POSTFIX)) { String targetUriHost = InetAddress.getByName(targetUri.getHost()).getHostAddress(); // remove leading zeros per block targetUriHost = targetUriHost.replaceAll(":0000", ":0"); targetUriHost = targetUriHost.replaceAll(":000", ":0"); targetUriHost = targetUriHost.replaceAll(":00", ":0"); targetUriHost = targetUriHost.replaceAll("(:0)([ABCDEFabcdef123456789])", ":$2"); // return shortened IP targetUriHost = targetUriHost.replaceAll("((?:(?:^|:)0\\b){2,}):?(?!\\S*\\b\\1:0\\b)(\\S*)", "::$2"); log.debug("Target host: " + targetUriHost); String targetUriPath = targetUri.getRawPath(); log.debug("Target path: " + targetUriPath); if (IPAddressUtil.isIPv6LiteralAddress(targetUriHost)) { targetUriHost = "[" + targetUriHost + "]"; } targetUri = toThing(URI.create("http://" + targetUriHost + httpRequest.getUri())); log.debug("Shortened target URI: " + targetUri); } URI uriToCheck = targetUri; if ((uriToCheck.getQuery() != null) && (uriToCheck.getQuery().equals("html"))) { uriToCheck = toThing(URI.create("http://" + targetUri.getHost() + targetUri.getPath())); } if (entities.containsKey(uriToCheck)) { Backend backend = entities.get(uriToCheck); try { ctx.getPipeline().remove("Backend to handle request"); } catch (NoSuchElementException ex) { // Fine. There was no handler to be removed. } ctx.getPipeline().addLast("Backend to handle request", backend); log.debug("Forward request to " + backend); } else if (virtualEntities.containsKey(uriToCheck)) { Backend backend = virtualEntities.get(uriToCheck); try { ctx.getPipeline().remove("Backend to handle request"); } catch (NoSuchElementException ex) { // Fine. There was no handler to be removed. } ctx.getPipeline().addLast("Backend to handle request", backend); log.debug("Forward request to " + backend); } // else if (targetUriPath.equals(PATH_TO_SERVER_LIST)) { // // Handle request for resource at path ".well-known/core" // StringBuilder buf = new StringBuilder(); // for(URI entity: getServices()) { // buf.append(toThing(entity).toString() + "\n"); // } // Channels.write(ctx.getChannel(), // Answer.create(buf.toString()).setMime("text/plain")); // return; // } // else if("/visualizer".equals(targetUriPath)){ // try { // ctx.getPipeline().remove("Backend to handle request"); // } // catch(NoSuchElementException ex) { // //Fine. There was no handler to be removed. // } // ctx.getPipeline().addLast("VisualizerService", VisualizerService.getInstance()); // log.debug("Forward request to visualizer."); // } /*else if(targetUriPath.startsWith(SERVER_PATH_TO_SLSE_UI)) { String f = LOCAL_PATH_TO_SLSE_UI + targetUriPath.substring(SERVER_PATH_TO_SLSE_UI.length()); Channels.write(ctx.getChannel(), Answer.create(new File(f)).setMime("text/n3")); }*/ else if ("/".equals(targetUri.getRawPath())) { HttpResponse httpResponse = new DefaultHttpResponse(httpRequest.getProtocolVersion(), HttpResponseStatus.OK); httpResponse.setContent(getHtmlListOfServices()); ChannelFuture future = Channels.write(ctx.getChannel(), httpResponse); future.addListener(ChannelFutureListener.CLOSE); return; } else if (httpRequest.getUri().endsWith("spitfire-logo.png") || (httpRequest.getUri().endsWith("favicon.ico"))) { File img; if (httpRequest.getUri().endsWith("spitfire-logo.png")) { img = new File("spitfire-logo.png"); } else { img = new File("favicon.ico"); } int imgLength = (int) img.length(); FileInputStream in = new FileInputStream(img); byte[] imgMemory = new byte[imgLength]; in.read(imgMemory); in.close(); HttpResponse httpResponse = new DefaultHttpResponse(httpRequest.getProtocolVersion(), HttpResponseStatus.OK); httpResponse.setContent(ChannelBuffers.wrappedBuffer(imgMemory)); ChannelFuture future = Channels.write(ctx.getChannel(), httpResponse); future.addListener(ChannelFutureListener.CLOSE); if (httpRequest.getUri().endsWith("spitfire-logo.png")) { log.debug("Served request for Spitfire image."); } else { log.debug("Served favicon."); } return; } ctx.sendUpstream(e); } private ChannelBuffer getHtmlListOfServices() { String html = HtmlCreator.createMainPage(uiElements, entities); return ChannelBuffers.wrappedBuffer(html.getBytes(Charset.forName("UTF-8"))); } /** Return URIs for all known services. */ public Iterable<URI> getServices() { return entities.keySet(); } /** * Will be called when an entity has been created. uri may be null in which case the return value * will be a newly allocated URI for the entity. */ public URI entityCreated(URI uri, Backend backend) { if (uri == null) { uri = nextEntityURI(); } uri = toThing(uri); if (!(entities.get(uri) == backend)) { entities.put(uri, backend); log.debug("New entity created: " + uri); } return uri; } public URI virtualEntityCreated(URI uri, Backend backend) { uri = toThing(uri); if (!(virtualEntities.get(uri) == backend)) { virtualEntities.put(uri, backend); log.debug("New virtual entity created: " + uri); } return uri; } public boolean entityDeleted(URI uri, Backend backend) { uri = toThing(uri); boolean succesful = entities.remove(uri, backend); if (succesful) { log.debug("Succesfully deleted " + uri); } else { log.debug("Could not delete: " + uri); } return succesful; } public boolean virtualEntityDeleted(URI uri, Backend backend) { uri = toThing(uri); boolean succesful = virtualEntities.remove(uri, backend); if (succesful) { log.debug("Succesfully deleted " + uri); } else { log.debug("Could not delete: " + uri); } return succesful; } public Backend getBackend(String elementSE) { Backend b = entities.get(elementSE); if (b == null) { URI uri = URI.create(SSP_DNS_NAME).resolve(elementSE).normalize(); String path = uri.getRawPath(); String pathPart = path.substring(0, path.indexOf("/")); b = backends.get(pathPart); } return b; } }
@Override public int getInt(String key, int defaultValue) { return config.getInt(key, defaultValue); }
private Object sendMessage( CreditCard creditCard, Money amount, Money tax, InetAddress userIp, boolean verify) throws IOException, CommerceException { URL url = new URL(configuration.getString("jcatapult.commerce.aim.url")); String username = configuration.getString("jcatapult.commerce.aim.username"); String password = configuration.getString("jcatapult.commerce.aim.password"); if (logger.isLoggable(Level.FINEST)) { logger.finest("Contacting AIM with this info"); logger.finest("URL: " + url.toExternalForm()); logger.finest("Username: "******"Password: "******"x_version=3.1&"); build.append("x_delim_data=TRUE&"); build.append("x_relay_response=FALSE&"); build.append("x_login="******"&"); build.append("x_tran_key=").append(password).append("&"); build.append("x_method=CC&"); build.append("x_delim_char=|&"); if (verify) { build.append("x_type=AUTH_ONLY&"); } else { build.append("x_type=AUTH_CAPTURE&"); } if (configuration.getBoolean("jcatapult.commerce.aim.test")) { build.append("x_test_request=TRUE&"); } if (!creditCard.isVerified()) { build.append("x_card_code=").append(creditCard.getSvn()).append("&"); build.append("x_first_name=").append(creditCard.getFirstName()).append("&"); build.append("x_last_name=").append(creditCard.getLastName()).append("&"); build.append("x_address=").append(creditCard.getAddress().getStreet1()).append("&"); build.append("x_city=").append(creditCard.getAddress().getCity()).append("&"); build.append("x_state=").append(creditCard.getAddress().getState()).append("&"); build.append("x_zip=").append(creditCard.getAddress().getPostalCode()).append("&"); build.append("x_country=").append(creditCard.getAddress().getCountry()).append("&"); build.append("x_customer_ip=").append(userIp.toString()).append("&"); } if (tax != null) { build.append("x_tax=").append(tax.toString()).append("&"); } build.append("x_amount=").append(amount.toString()).append("&"); build.append("x_currency_code=").append(amount.getCurrency().getCurrencyCode()).append("&"); build.append("x_card_num=").append(creditCard.getNumber()).append("&"); build.append("x_exp_date=").append(creditCard.getExpirationDate()); huc.setConnectTimeout( configuration.getInt("jcatapult.commerce.aim.connectTimeoutSeconds", 60) * 1000); huc.setReadTimeout( configuration.getInt("jcatapult.commerce.aim.readTimeoutSeconds", 180) * 1000); huc.setUseCaches(false); huc.setDoInput(true); huc.setDoOutput(true); huc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); huc.connect(); OutputStream os = huc.getOutputStream(); os.write(build.toString().getBytes()); os.flush(); os.close(); BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream())); String response = br.readLine(); br.close(); // logger.finest("Response from AIM is [" + response + "]"); String[] parts = split(response); if (parts.length < 39) { throw new CommerceException("Invalid response from the Gateway."); } int responseCode = Integer.valueOf(parts[0]); String transactionID = null; CommerceError error = null; if (responseCode == 1) { transactionID = parts[6]; } else { error = getError(parts[0], parts[2], parts[3], parts[4], parts[5]); } if (verify) { return new VerifyResult(error); } return new ChargeResult(transactionID, error, parts[0], parts[2], parts[3], parts[4], parts[5]); }