List of usage examples for org.apache.hadoop.conf Configuration getInt
public int getInt(String name, int defaultValue)
name
property as an int
. From source file:com.alibaba.wasp.storage.StorageActionManager.java
License:Apache License
/** * default constructor//ww w . j a va 2 s.c om * * @param conf */ public StorageActionManager(Configuration conf) throws IOException { try { hbc = HBaseConfiguration.create(conf); pool = new HTablePool(hbc, conf.getInt(FConstants.WASP_FSERVER_MAX_TABLE_COUNT, MAX_TABLE_COUNT)); admin = new HBaseAdmin(hbc); } catch (MasterNotRunningException e) { LOG.error("HBaseActionManager initlized failed.HMaster is not running.", e); throw new IOException(e); } catch (ZooKeeperConnectionException e) { LOG.error("HBaseActionManager initlized failed.Cann't connect zookeeper.", e); throw new IOException(e); } }
From source file:com.alibaba.wasp.zookeeper.ZKConfig.java
License:Apache License
/** * Make a Properties object holding ZooKeeper config equivalent to zoo.cfg. * If there is a zoo.cfg in the classpath, simply read it in. Otherwise parse * the corresponding config options from the Wasp XML configs and generate * the appropriate ZooKeeper properties. * @param conf Configuration to read from. * @return Properties holding mappings representing ZooKeeper zoo.cfg file. *///from w w w.j a v a 2s . c om public static Properties makeZKProps(Configuration conf) { // First check if there is a zoo.cfg in the CLASSPATH. If so, simply read // it and grab its configuration properties. ClassLoader cl = FQuorumPeer.class.getClassLoader(); final InputStream inputStream = cl.getResourceAsStream(FConstants.ZOOKEEPER_CONFIG_NAME); if (inputStream != null) { try { return parseZooCfg(conf, inputStream); } catch (IOException e) { LOG.warn("Cannot read " + FConstants.ZOOKEEPER_CONFIG_NAME + ", loading from XML files", e); } } // Otherwise, use the configuration options from Wasp's XML files. Properties zkProperties = new Properties(); // Directly map all of the wasp.zookeeper.property.KEY properties. for (Entry<String, String> entry : conf) { String key = entry.getKey(); if (key.startsWith(FConstants.ZK_CFG_PROPERTY_PREFIX)) { String zkKey = key.substring(FConstants.ZK_CFG_PROPERTY_PREFIX_LEN); String value = entry.getValue(); // If the value has variables substitutions, need to do a get. if (value.contains(VARIABLE_START)) { value = conf.get(key); } zkProperties.put(zkKey, value); } } // If clientPort is not set, assign the default. if (zkProperties.getProperty(FConstants.CLIENT_PORT_STR) == null) { zkProperties.put(FConstants.CLIENT_PORT_STR, FConstants.DEFAULT_ZOOKEPER_CLIENT_PORT); } // Create the server.X properties. int peerPort = conf.getInt("wasp.zookeeper.peerport", 2888); int leaderPort = conf.getInt("wasp.zookeeper.leaderport", 3888); final String[] serverHosts = conf.getStrings(FConstants.ZOOKEEPER_QUORUM, FConstants.LOCALHOST); for (int i = 0; i < serverHosts.length; ++i) { String serverHost = serverHosts[i]; String address = serverHost + ":" + peerPort + ":" + leaderPort; String key = "server." + i; zkProperties.put(key, address); } return zkProperties; }
From source file:com.alibaba.wasp.zookeeper.ZKUtil.java
License:Apache License
public static RecoverableZooKeeper connect(Configuration conf, String ensemble, Watcher watcher, final String descriptor) throws IOException { if (ensemble == null) { throw new IOException("Unable to determine ZooKeeper ensemble"); }//from w w w . ja v a2 s.co m int timeout = conf.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT); LOG.debug(descriptor + " opening connection to ZooKeeper with ensemble (" + ensemble + ")"); int retry = conf.getInt("zookeeper.recovery.retry", 3); int retryIntervalMillis = conf.getInt("zookeeper.recovery.retry.intervalmill", 1000); zkDumpConnectionTimeOut = conf.getInt("zookeeper.dump.connection.timeout", 1000); return new RecoverableZooKeeper(ensemble, timeout, watcher, retry, retryIntervalMillis); }
From source file:com.alibaba.wasp.zookeeper.ZKUtil.java
License:Apache License
/** * Waits for HBase installation's base (parent) znode to become available. * * @throws java.io.IOException/*w ww.j a va2 s .c om*/ * on ZK errors */ public static void waitForBaseZNode(Configuration conf) throws IOException { LOG.info("Waiting until the base znode is available"); String parentZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); ZooKeeper zk = new ZooKeeper(ZKConfig.getZKQuorumServersString(conf), conf.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT), EmptyWatcher.instance); final int maxTimeMs = 10000; final int maxNumAttempts = maxTimeMs / HConstants.SOCKET_RETRY_WAIT_MS; KeeperException keeperEx = null; try { try { for (int attempt = 0; attempt < maxNumAttempts; ++attempt) { try { if (zk.exists(parentZNode, false) != null) { LOG.info("Parent znode exists: " + parentZNode); keeperEx = null; break; } } catch (KeeperException e) { keeperEx = e; } Threads.sleepWithoutInterrupt(HConstants.SOCKET_RETRY_WAIT_MS); } } finally { zk.close(); } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } if (keeperEx != null) { throw new IOException(keeperEx); } }
From source file:com.alimama.quanjingmonitor.kmeans.KMeansClusterCombiner.java
License:Apache License
@Override protected void setup(Context context) throws IOException, InterruptedException { super.setup(context); this.clusters.clear(); Configuration conf = context.getConfiguration(); this.rep = conf.getInt(KMeansDriver.CLUSTER_CONVERGENCE_ABTEST_REP, 2); try {/*w w w .jav a 2s .c o m*/ String clusterPath = conf.get(KMeansDriver.CLUSTER_PATH_KEY); if (clusterPath != null && clusterPath.length() > 0) { KmeansPublic.configureWithClusterInfo(conf, new Path(clusterPath), clusters); if (clusters.isEmpty()) { throw new IllegalStateException("No clusters found. Check your -c path."); } this.setClusterMap(clusters); } } catch (Throwable e) { throw new IllegalStateException(e); } }
From source file:com.alimama.quanjingmonitor.kmeans.KMeansClusterReduce.java
License:Apache License
@Override protected void setup(Context context) throws IOException, InterruptedException { super.setup(context); this.clusters.clear(); Configuration conf = context.getConfiguration(); parse.setup(conf);//from w w w . ja v a2 s.com this.rep = conf.getInt(KMeansDriver.CLUSTER_CONVERGENCE_ABTEST_REP, 2); try { String clusterPath = conf.get(KMeansDriver.CLUSTER_PATH_KEY); if (clusterPath != null && clusterPath.length() > 0) { KmeansPublic.configureWithClusterInfo(conf, new Path(clusterPath), clusters); if (clusters.isEmpty()) { throw new IllegalStateException("No clusters found. Check your -c path."); } this.setClusterMap(clusters); } } catch (Throwable e) { throw new IllegalStateException(e); } }
From source file:com.aliyun.fs.oss.blk.JetOssFileSystemStore.java
License:Apache License
public JetOssFileSystemStore(OSSClient ossClient, String bucket, Configuration conf) { this.conf = conf; this.ossClient = ossClient; this.bucket = bucket; this.bufferSize = conf.getInt("io.file.buffer.size", 4096); }
From source file:com.aliyun.fs.oss.blk.JetOssFileSystemStore.java
License:Apache License
public void initialize(URI uri, Configuration conf) throws IOException { if (uri.getHost() == null) { throw new IllegalArgumentException("Invalid hostname in URI " + uri); }// ww w. j a v a 2 s . c o m this.conf = conf; String userInfo = uri.getUserInfo(); if (userInfo != null) { String[] ossCredentials = userInfo.split(":"); if (ossCredentials.length >= 2) { accessKeyId = ossCredentials[0]; accessKeySecret = ossCredentials[1]; } if (ossCredentials.length == 3) { securityToken = ossCredentials[2]; } } String host = uri.getHost(); if (!StringUtils.isEmpty(host) && !host.contains(".")) { bucket = host; } else if (!StringUtils.isEmpty(host)) { bucket = host.substring(0, host.indexOf(".")); endpoint = host.substring(host.indexOf(".") + 1); } if (accessKeyId == null) { accessKeyId = conf.getTrimmed("fs.oss.accessKeyId"); } if (accessKeySecret == null) { accessKeySecret = conf.getTrimmed("fs.oss.accessKeySecret"); } if (securityToken == null) { securityToken = conf.getTrimmed("fs.oss.securityToken"); } if (endpoint == null) { endpoint = conf.getTrimmed("fs.oss.endpoint"); } ClientConfiguration cc = initializeOSSClientConfig(conf); if (securityToken == null) { this.ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret, cc); } else { this.ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret, securityToken, cc); } this.bufferSize = conf.getInt("io.file.buffer.size", 4096); }
From source file:com.aliyun.fs.oss.blk.JetOssFileSystemStore.java
License:Apache License
private ClientConfiguration initializeOSSClientConfig(Configuration conf) { ClientConfiguration cc = new ClientConfiguration(); cc.setConnectionTimeout(/* ww w .j ava 2 s. co m*/ conf.getInt("fs.oss.client.connection.timeout", ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT)); cc.setSocketTimeout( conf.getInt("fs.oss.client.socket.timeout", ClientConfiguration.DEFAULT_SOCKET_TIMEOUT)); cc.setConnectionTTL( conf.getLong("fs.oss.client.connection.ttl", ClientConfiguration.DEFAULT_CONNECTION_TTL)); cc.setMaxConnections(conf.getInt("fs.oss.connection.max", ClientConfiguration.DEFAULT_MAX_CONNECTIONS)); return cc; }
From source file:com.aliyun.fs.oss.blk.OssFileSystem.java
License:Apache License
private static FileSystemStore createDefaultStore(Configuration conf) { FileSystemStore store = new JetOssFileSystemStore(); RetryPolicy basePolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( conf.getInt("fs.oss.maxRetries", 4), conf.getLong("fs.oss.sleepTimeSeconds", 10), TimeUnit.SECONDS); Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); exceptionToPolicyMap.put(IOException.class, basePolicy); exceptionToPolicyMap.put(OssException.class, basePolicy); RetryPolicy methodPolicy = RetryPolicies.retryByException(RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);/*from w ww . j a va 2 s . c om*/ Map<String, RetryPolicy> methodNameToPolicyMap = new HashMap<String, RetryPolicy>(); methodNameToPolicyMap.put("storeBlock", methodPolicy); methodNameToPolicyMap.put("retrieveBlock", methodPolicy); return (FileSystemStore) RetryProxy.create(FileSystemStore.class, store, methodNameToPolicyMap); }