Java Code Examples for com.google.common.net.HostAndPort#getHostText()

The following examples show how to use com.google.common.net.HostAndPort#getHostText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamableRDDTest_Failures.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testBasicStream() throws Exception {
    StreamListener<ExecRow> sl = new StreamListener<>();
    HostAndPort hostAndPort = server.getHostAndPort();
    server.register(sl);
    JavaPairRDD<ExecRow, ExecRow> rdd = SpliceSpark.getContextUnsafe().parallelizePairs(tenRows, 2).mapToPair(new FailsFunction(3));
    StreamableRDD srdd = new StreamableRDD(rdd.values(), sl.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort());
    srdd.submit();
    Iterator<ExecRow> it = sl.getIterator();
    int count = 0;
    while (it.hasNext()) {
        ExecRow execRow = it.next();
        LOG.trace(execRow);
        count++;
        assertNotNull(execRow);
        assertTrue(execRow.getColumn(1).getInt() < 10);
    }
    assertEquals(10, count);
}
 
Example 2
Source File: Bootstrap.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
public boolean bootstrap(HostAndPort seed, 
                         Node localNode) throws SyncException {
    this.localNode = localNode;
    succeeded = false;
    SocketAddress sa =
            new InetSocketAddress(seed.getHostText(), seed.getPort());
    ChannelFuture future = bootstrap.connect(sa);
    future.awaitUninterruptibly();
    if (!future.isSuccess()) {
        logger.debug("Could not connect to " + seed, future.getCause());
        return false;
    }
    Channel channel = future.getChannel();
    logger.debug("[{}] Connected to {}", 
                 localNode != null ? localNode.getNodeId() : null,
                 seed);
    
    try {
        channel.getCloseFuture().await();
    } catch (InterruptedException e) {
        logger.debug("Interrupted while waiting for bootstrap");
        return succeeded;
    }
    return succeeded;
}
 
Example 3
Source File: StreamableRDDTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testBlocking() throws StandardException {
    StreamListener<ExecRow> sl = new StreamListener<>();
    HostAndPort hostAndPort = server.getHostAndPort();
    server.register(sl);

    List<Tuple2<ExecRow,ExecRow>> manyRows = new ArrayList<>();
    for(int i = 0; i < 10000; ++i) {
        manyRows.add(new Tuple2<ExecRow, ExecRow>(getExecRow(i, 1), getExecRow(i, 2)));
    }

    JavaPairRDD<ExecRow, ExecRow> rdd = SpliceSpark.getContextUnsafe().parallelizePairs(manyRows, 6);
    final StreamableRDD srdd = new StreamableRDD(rdd.values(), sl.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort());
    new Thread() {
        @Override
        public void run() {
            try {
                srdd.submit();
            } catch (Exception e) {
                LOG.error(e);
                throw new RuntimeException(e);
            }

        }
    }.start();
    Iterator<ExecRow> it = sl.getIterator();
    int count = 0;
    while (it.hasNext()) {
        ExecRow execRow = it.next();
        count++;
        assertNotNull(execRow);
    }
    assertEquals(10000, count);
}
 
Example 4
Source File: StreamableRDDTest_Failures.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testFailureAfterRecoveryWarmup() throws StandardException, FileNotFoundException, UnsupportedEncodingException {
    int size = 100000;
    int batches = 2;
    int batchSize = 512;
    StreamListener<ExecRow> sl = new StreamListener<>(-1, 0, batches, batchSize);
    HostAndPort hostAndPort = server.getHostAndPort();
    server.register(sl);

    List<Tuple2<ExecRow,ExecRow>> manyRows = new ArrayList<>();
    for(int i = 0; i < size; ++i) {
        manyRows.add(new Tuple2<ExecRow, ExecRow>(getExecRow(i, 1), getExecRow(i, 2)));
    }

    JavaPairRDD<ExecRow, ExecRow> rdd = SpliceSpark.getContextUnsafe().parallelizePairs(manyRows, 2).sortByKey().mapToPair(new FailsTwiceFunction(10000, 2000));
    final StreamableRDD srdd = new StreamableRDD(rdd.values(), null, sl.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort(), batches, batchSize);
    new Thread() {
        @Override
        public void run() {
            try {
                srdd.submit();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    }.start();
    Iterator<ExecRow> it = sl.getIterator();
    int count = 0;
    while (it.hasNext()) {
        ExecRow execRow = it.next();
        assertNotNull(execRow);
        count++;
    }
    assertEquals(size, count);
}
 
Example 5
Source File: JcloudsUtil.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** @see #getReachableAddresses(NodeMetadata, Duration, Predicate) */
public static String getFirstReachableAddress(NodeMetadata node, Duration timeout, Predicate<? super HostAndPort> socketTester) {
    Iterable<HostAndPort> addresses = getReachableAddresses(node, timeout, socketTester);
    HostAndPort address = Iterables.getFirst(addresses, null);
    if (address != null) {
        return address.getHostText();
    } else {
        throw new IllegalStateException("No reachable IPs for " + node + "; check whether the node is " +
                "reachable and whether it meets the requirements of the HostAndPort tester: " + socketTester);
    }
}
 
Example 6
Source File: AbstractControllerImpl.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
/** returns URL, if it can be inferred; null otherwise */
protected String inferUrl(boolean requireManagementAccessible) {
    String domain = getDomainWithoutWildcard();
    Integer port = checkNotNull(getPort(), "no port configured (the requested port may be in use)");
    if (requireManagementAccessible) {
        HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, port);
        if (accessible!=null) {
            domain = accessible.getHostText();
            port = accessible.getPort();
        }
    }
    if (domain==null) domain = Machines.findSubnetHostname(this).orNull();
    return inferUrl(domain, Optional.of(port));
}
 
Example 7
Source File: MongoDBTestHelper.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
private static MongoClient clientForServer(AbstractMongoDBServer server) {
    try {
        HostAndPort hap = BrooklynAccessUtils.getBrooklynAccessibleAddress(server, server.getAttribute(MongoDBServer.PORT));
        return new MongoClient(hap.getHostText(), hap.getPort());
    } catch (Exception e) {
        // Fail whatever test called this method.
        throw Throwables.propagate(e);
    }
}
 
Example 8
Source File: PortForwardManagerImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void associateImpl(String publicIpId, HostAndPort publicEndpoint, Location l, int privatePort) {
    synchronized (mutex) {
        String publicIp = publicEndpoint.getHostText();
        int publicPort = publicEndpoint.getPort();
        recordPublicIpHostname(publicIpId, publicIp);
        PortMapping mapping = new PortMapping(publicIpId, publicEndpoint, l, privatePort);
        PortMapping oldMapping = getPortMappingWithPublicSide(publicIpId, publicPort);
        log.debug(this+" associating public "+publicEndpoint+" on "+publicIpId+" with private port "+privatePort+" at "+l+" ("+mapping+")"
                +(oldMapping == null ? "" : " (overwriting "+oldMapping+" )"));
        mappings.put(makeKey(publicIpId, publicPort), mapping);
    }
    onChanged();
}
 
Example 9
Source File: StreamableRDDTest_Failures.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testFailureAfterLimit() throws StandardException {
    StreamListener<ExecRow> sl = new StreamListener<>(40000, 300);
    HostAndPort hostAndPort = server.getHostAndPort();
    server.register(sl);

    List<Tuple2<ExecRow,ExecRow>> manyRows = new ArrayList<>();
    for(int i = 0; i < 100000; ++i) {
        manyRows.add(new Tuple2<ExecRow, ExecRow>(getExecRow(i, 1), getExecRow(i, 2)));
    }

    JavaPairRDD<ExecRow, ExecRow> rdd = SpliceSpark.getContextUnsafe().parallelizePairs(manyRows, 13).mapToPair(new FailsFunction(40301));;
    final StreamableRDD srdd = new StreamableRDD(rdd.values(), sl.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort());
    new Thread() {
        @Override
        public void run() {
            try {
                srdd.submit();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    }.start();
    Iterator<ExecRow> it = sl.getIterator();
    int count = 0;
    int first = 300;
    while (it.hasNext()) {
        ExecRow execRow = it.next();
        assertNotNull(execRow);
        assertEquals(count+first, execRow.getColumn(1).getInt());
        count++;
    }
    assertEquals(40000, count);
}
 
Example 10
Source File: ResolvedHostnameCacheFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionSucceeded(String serverHostAndPort, InetSocketAddress resolvedRemoteAddress) {
    // the address *should* always be resolved at this point
    InetAddress resolvedAddress = resolvedRemoteAddress.getAddress();

    if (resolvedAddress != null) {
        // place the resolved host into the hostname cache, so subsequent requests will be able to identify the IP address
        HostAndPort parsedHostAndPort = HostAndPort.fromString(serverHostAndPort);
        String host = parsedHostAndPort.getHostText();

        if (host != null && !host.isEmpty()) {
            resolvedAddresses.put(host, resolvedAddress.getHostAddress());
        }
    }
}
 
Example 11
Source File: StreamableRDDTest_Failures.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testFailureBeforeOffset() throws StandardException {
    StreamListener<ExecRow> sl = new StreamListener<>(40000, 300);
    HostAndPort hostAndPort = server.getHostAndPort();
    server.register(sl);

    List<Tuple2<ExecRow,ExecRow>> manyRows = new ArrayList<>();
    for(int i = 0; i < 100000; ++i) {
        manyRows.add(new Tuple2<ExecRow, ExecRow>(getExecRow(i, 1), getExecRow(i, 2)));
    }

    JavaPairRDD<ExecRow, ExecRow> rdd = SpliceSpark.getContextUnsafe().parallelizePairs(manyRows, 13).mapToPair(new FailsFunction(200));;
    final StreamableRDD srdd = new StreamableRDD(rdd.values(), sl.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort());
    new Thread() {
        @Override
        public void run() {
            try {
                srdd.submit();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    }.start();
    Iterator<ExecRow> it = sl.getIterator();
    int count = 0;
    int first = 300;
    while (it.hasNext()) {
        ExecRow execRow = it.next();
        assertNotNull(execRow);
        assertEquals(count+first, execRow.getColumn(1).getInt());
        count++;
    }
    assertEquals(40000, count);
}
 
Example 12
Source File: CodahaleMetricsProvider.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private ScheduledReporter createAndGetConfiguredGraphiteReporter(String prefix, String graphiteHost) {
    LOG.info("Configuring Graphite reporter. Sendig data to host:port {}", graphiteHost);
    HostAndPort addr = HostAndPort.fromString(graphiteHost);

    final Graphite graphite = new Graphite(
            new InetSocketAddress(addr.getHostText(), addr.getPort()));

    return GraphiteReporter.forRegistry(metrics)
            .prefixedWith(prefix)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);
}
 
Example 13
Source File: StreamableRDDTest_Failures.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testFailureAfterOffset() throws StandardException {
    StreamListener<ExecRow> sl = new StreamListener<>(40000, 300);
    HostAndPort hostAndPort = server.getHostAndPort();
    server.register(sl);

    List<Tuple2<ExecRow,ExecRow>> manyRows = new ArrayList<>();
    for(int i = 0; i < 100000; ++i) {
        manyRows.add(new Tuple2<ExecRow, ExecRow>(getExecRow(i, 1), getExecRow(i, 2)));
    }

    JavaPairRDD<ExecRow, ExecRow> rdd = SpliceSpark.getContextUnsafe().parallelizePairs(manyRows, 13).mapToPair(new FailsFunction(14000));;
    final StreamableRDD srdd = new StreamableRDD(rdd.values(), sl.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort());
    new Thread() {
        @Override
        public void run() {
            try {
                srdd.submit();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    }.start();
    Iterator<ExecRow> it = sl.getIterator();
    int count = 0;
    int first = 300;
    while (it.hasNext()) {
        ExecRow execRow = it.next();
        assertNotNull(execRow);
        assertEquals(count+first, execRow.getColumn(1).getInt());
        count++;
    }
    assertEquals(40000, count);
}
 
Example 14
Source File: StreamableRDDTest_Failures.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testBlockingLarge() throws StandardException, FileNotFoundException, UnsupportedEncodingException {
    int size = 100000;
    int batches = 2;
    int batchSize = 512;
    StreamListener<ExecRow> sl = new StreamListener<>(-1, 0, batches, batchSize);
    HostAndPort hostAndPort = server.getHostAndPort();
    server.register(sl);

    List<Tuple2<ExecRow,ExecRow>> manyRows = new ArrayList<>();
    for(int i = 0; i < size; ++i) {
        manyRows.add(new Tuple2<ExecRow, ExecRow>(getExecRow(i, 1), getExecRow(i, 2)));
    }

    JavaPairRDD<ExecRow, ExecRow> rdd = SpliceSpark.getContextUnsafe().parallelizePairs(manyRows, 12).sortByKey().mapToPair(new FailsFunction(10000));
    final StreamableRDD srdd = new StreamableRDD(rdd.values(), null, sl.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort(), batches, batchSize);
    new Thread() {
        @Override
        public void run() {
            try {
                srdd.submit();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    }.start();
    Iterator<ExecRow> it = sl.getIterator();
    int count = 0;
    while (it.hasNext()) {
        ExecRow execRow = it.next();
        assertNotNull(execRow);
        count++;
    }
    assertEquals(size, count);
}
 
Example 15
Source File: CassandraConfiguration.java    From emodb with Apache License 2.0 4 votes vote down vote up
private com.datastax.driver.core.Cluster.Builder newCqlDriverBuilder(ConnectionPoolConfiguration poolConfig,
                                                                     MetricRegistry metricRegistry) {
    performHostDiscovery(metricRegistry);

    String[] seeds = _seeds.split(",");
    List<String> contactPoints = Lists.newArrayListWithCapacity(seeds.length);

    // Each seed may be a host name or a host name and port (e.g.; "1.2.3.4" or "1.2.3.4:9160").  These need
    // to be converted into host names only.
    for (String seed : seeds) {
        HostAndPort hostAndPort = HostAndPort.fromString(seed);
        seed = hostAndPort.getHostText();
        if (hostAndPort.hasPort()) {
            if (hostAndPort.getPort() == _thriftPort) {
                _log.debug("Seed {} found using RPC port; swapping for native port {}", seed, _cqlPort);
            } else if (hostAndPort.getPort() != _cqlPort) {
                throw new IllegalArgumentException(String.format(
                        "Seed %s found with invalid port %s.  The port must match either the RPC (thrift) port %s " +
                        "or the native (CQL) port %s", seed, hostAndPort.getPort(), _thriftPort, _cqlPort));
            }
        }

        contactPoints.add(seed);
    }

    PoolingOptions poolingOptions = new PoolingOptions();
    if (poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).isPresent()) {
        poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).get());
    }
    if (poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).isPresent()) {
        poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).get());
    }

    SocketOptions socketOptions = new SocketOptions();
    if (poolConfig.getConnectTimeout().or(getConnectTimeout()).isPresent()) {
        socketOptions.setConnectTimeoutMillis(poolConfig.getConnectTimeout().or(getConnectTimeout()).get());
    }
    if (poolConfig.getSocketTimeout().or(getSocketTimeout()).isPresent()) {
        socketOptions.setReadTimeoutMillis(poolConfig.getSocketTimeout().or(getSocketTimeout()).get());
    }

    AuthProvider authProvider = _authenticationCredentials != null
            ? new PlainTextAuthProvider(_authenticationCredentials.getUsername(), _authenticationCredentials.getPassword())
            : AuthProvider.NONE;

    return com.datastax.driver.core.Cluster.builder()
            .addContactPoints(contactPoints.toArray(new String[contactPoints.size()]))
            .withPort(_cqlPort)
            .withPoolingOptions(poolingOptions)
            .withSocketOptions(socketOptions)
            .withRetryPolicy(Policies.defaultRetryPolicy())
            .withAuthProvider(authProvider);
}
 
Example 16
Source File: CassandraThriftFacade.java    From emodb with Apache License 2.0 4 votes vote down vote up
/** Note: <code>seeds</code> may be a single host or comma-delimited list. */
public static CassandraThriftFacade forSeedsAndPort(String seeds, int defaultPort) {
    final String seed = seeds.contains(",") ? seeds.substring(0, seeds.indexOf(',')) : seeds;
    HostAndPort host = HostAndPort.fromString(seed).withDefaultPort(defaultPort);
    return new CassandraThriftFacade(new TFramedTransport(new TSocket(host.getHostText(), host.getPort())));
}
 
Example 17
Source File: DockerClientFactory.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This method returns the DockerClient dependent on the current OS.
 * 
 * @return
 * @throws DockerCertificateException
 * @throws IOException
 * @throws InterruptedException
 */
public DockerClient getDockerClient() throws DockerCertificateException, IOException, InterruptedException {
	DockerClient client = null;

	// If this is not Linux, then we have to find DOCKER_HOST
	if (!Platform.getOS().equals(Platform.OS_LINUX)) {

		// See if we can get the DOCKER_HOST environment variaable
		String dockerHost = System.getenv("DOCKER_HOST");
		if (dockerHost == null) {

			// If not, run a script to see if we can get it
			File script = getDockerConnectionScript();
			String[] scriptExec = null;
			if (Platform.getOS().equals(Platform.OS_MACOSX)) {
				scriptExec = new String[] { script.getAbsolutePath() };
			} else if (Platform.getOS().equals(Platform.OS_WIN32)) {
				scriptExec = new String[] { "cmd.exe", "/C", script.getAbsolutePath() };
			}

			// Execute the script to get the DOCKER vars.
			Process process = new ProcessBuilder(scriptExec).start();
			process.waitFor();
			int exitValue = process.exitValue();
			if (exitValue == 0) {

				// Read them into a Properties object
				InputStream processInputStream = process.getInputStream();
				Properties dockerSettings = new Properties();
				// Properties.load screws up windows path separators
				// so if windows, just get the string from the stream
				if (Platform.getOS().equals(Platform.OS_WIN32)) {
					String result = streamToString(processInputStream).trim();
					String[] dockerEnvs = result.split(System.lineSeparator());
					for (String s : dockerEnvs) {
						String[] env = s.split("=");
						dockerSettings.put(env[0], env[1]);
					}
				} else {
					dockerSettings.load(processInputStream);
				}
				
				// Create the Builder object that wil build the DockerClient
				Builder builder = new Builder();

				// Get the DOCKER_HOST and CERT_PATH vars
				String endpoint = dockerSettings.getProperty("DOCKER_HOST");
				Path dockerCertPath = Paths.get(dockerSettings.getProperty("DOCKER_CERT_PATH"));

				System.out.println("DOCKERHOST: " + endpoint);
				System.out.println("DOCKER CERT PATH: " + dockerSettings.getProperty("DOCKER_CERT_PATH"));
				// Set up the certificates
				DockerCertificates certs = DockerCertificates.builder().dockerCertPath(dockerCertPath).build();

				// Set the data need for the builder.
				String stripped = endpoint.replaceAll(".*://", "");
				HostAndPort hostAndPort = HostAndPort.fromString(stripped);
				String hostText = hostAndPort.getHostText();
				String scheme = certs != null ? "https" : "http";
				int port = hostAndPort.getPortOrDefault(2375);
				String address = hostText;
				builder.uri(scheme + "://" + address + ":" + port);
				if (certs != null) {
					builder.dockerCertificates(certs);
				}

				// Build the Dockerclient!
				client = builder.build();

			} else {
				// log what happened if the process did not end as expected
				// an exit value of 1 should indicate no connection found
				InputStream processErrorStream = process.getErrorStream();
				String errorMessage = streamToString(processErrorStream);
				logger.error("Error in getting DOCKER variables: " + errorMessage);
			}
		} else {
			client = DefaultDockerClient.fromEnv().build();
		}
	} else {
		// It was equal to Linux, so just use the default stuff.
		client = DefaultDockerClient.fromEnv().build();
	}

	return client;
}
 
Example 18
Source File: StreamableRDDTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testConcurrentQueries() throws StandardException, ExecutionException, InterruptedException {
    final StreamListener<ExecRow> sl1 = new StreamListener<>();
    final StreamListener<ExecRow> sl2 = new StreamListener<>();
    final StreamListener<ExecRow> sl3 = new StreamListener<>();
    HostAndPort hostAndPort = server.getHostAndPort();
    server.register(sl1);
    server.register(sl2);
    server.register(sl3);

    List<Tuple2<ExecRow,ExecRow>> manyRows = new ArrayList<>();
    for(int i = 0; i < 100000; ++i) {
        manyRows.add(new Tuple2<ExecRow, ExecRow>(getExecRow(i, 1), getExecRow(i, 2)));
    }

    JavaPairRDD<ExecRow, ExecRow> rdd = SpliceSpark.getContextUnsafe().parallelizePairs(manyRows, 12);
    final StreamableRDD srdd1 = new StreamableRDD(rdd.values(), sl1.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort());
    final StreamableRDD srdd2 = new StreamableRDD(rdd.values().map(new Function<ExecRow,ExecRow>() {
        @Override
        public ExecRow call(ExecRow o) throws Exception {
            o.getColumn(1).setValue(0);
            return o;
        }
    }), sl2.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort());
    final StreamableRDD srdd3 = new StreamableRDD(rdd.values(), sl3.getUuid(), hostAndPort.getHostText(), hostAndPort.getPort());
    for (final StreamableRDD srdd : Arrays.asList(srdd1, srdd2, srdd3)) {
        new Thread() {
            @Override
            public void run() {
                try {
                    srdd.submit();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }

            }
        }.start();
    }
    // We collect them asynchronously into memory so we are able to iterate over them at the same time. Otherwise
    // tasks for the third RDD might be blocked by tasks in other RDDs, and we are not consuming elements from the
    // other iterators so they can become unblocked.
    ExecutorService executor = Executors.newFixedThreadPool(3);
    Future<List<ExecRow>> future1 = executor.submit(new Callable<List<ExecRow>>() {
        @Override
        public List<ExecRow> call() throws Exception {
            return IteratorUtils.toList(sl1.getIterator());
        }
    });
    Future<List<ExecRow>> future2 = executor.submit(new Callable<List<ExecRow>>() {
        @Override
        public List<ExecRow> call() throws Exception {
            return IteratorUtils.toList(sl2.getIterator());
        }
    });
    Future<List<ExecRow>> future3 = executor.submit(new Callable<List<ExecRow>>() {
        @Override
        public List<ExecRow> call() throws Exception {
            return IteratorUtils.toList(sl3.getIterator());
        }
    });
    Iterator<ExecRow> it1 = future1.get().iterator();
    Iterator<ExecRow> it2 = future2.get().iterator();
    Iterator<ExecRow> it3 = future3.get().iterator();
    int count = 0;
    while (it1.hasNext()) {
        ExecRow r1 = it1.next();
        ExecRow r2 = it2.next();
        ExecRow r3 = it3.next();
        count++;
        assertNotNull(r1);
        assertNotNull(r2);
        assertNotNull(r3);
        assertEquals(0, r2.getColumn(1).getInt());
        assertEquals(r1.getColumn(1), r3.getColumn(1));
        assertEquals(r1.getColumn(2), r2.getColumn(2));
    }
    assertEquals(100000, count);
}
 
Example 19
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected JcloudsWinRmMachineLocation createWinRmMachineLocation(
        ComputeService computeService, NodeMetadata node, Optional<Template> template,
        LoginCredentials userCredentials, HostAndPort winrmHostAndPort, ConfigBag setup) {

    Collection<JcloudsLocationCustomizer> customizers = getCustomizers(setup);
    Collection<MachineLocationCustomizer> machineCustomizers = getMachineCustomizers(setup);
    Map<?,?> winrmConfig = extractWinrmConfig(setup, node);
    String nodeAvailabilityZone = extractAvailabilityZone(setup, node);
    String nodeRegion = extractRegion(setup, node);
    if (nodeRegion == null) {
        // e.g. rackspace doesn't have "region", so rackspace-uk is best we can say (but zone="LON")
        nodeRegion = extractProvider(setup, node);
    }
    
    String address = winrmHostAndPort.getHostText();
    String displayName = getPublicHostnameGeneric(node, setup, Optional.of(address));

    final Object password = winrmConfig.get(WinRmMachineLocation.PASSWORD.getName()) != null
            ? winrmConfig.get(WinRmMachineLocation.PASSWORD.getName())
            : userCredentials.getOptionalPassword().orNull();
    if (isManaged()) {
        final LocationSpec<JcloudsWinRmMachineLocation> spec = LocationSpec.create(JcloudsWinRmMachineLocation.class)
                .configure(winrmConfig)
                .configure("jcloudsParent", this)
                .configure("displayName", displayName)
                .configure("address", address)
                .configure(WinRmMachineLocation.WINRM_CONFIG_PORT, winrmHostAndPort.getPort())
                .configure(WinRmMachineLocation.USER.getName(), userCredentials.getUser())
                .configure(WinRmMachineLocation.PASSWORD.getName(), password)
                .configure("node", node)
                .configureIfNotNull(CLOUD_AVAILABILITY_ZONE_ID, nodeAvailabilityZone)
                .configureIfNotNull(CLOUD_REGION_ID, nodeRegion)
                .configure(CALLER_CONTEXT, setup.get(CALLER_CONTEXT))
                .configure(SshMachineLocation.DETECT_MACHINE_DETAILS, setup.get(SshMachineLocation.DETECT_MACHINE_DETAILS))
                .configureIfNotNull(SshMachineLocation.SCRIPT_DIR, setup.get(SshMachineLocation.SCRIPT_DIR))
                .configureIfNotNull(USE_PORT_FORWARDING, setup.get(USE_PORT_FORWARDING))
                .configureIfNotNull(PORT_FORWARDER, setup.get(PORT_FORWARDER))
                .configureIfNotNull(PORT_FORWARDING_MANAGER, setup.get(PORT_FORWARDING_MANAGER))
                .configureIfNotNull(JCLOUDS_LOCATION_CUSTOMIZERS, customizers.size() > 0 ? customizers : null)
                .configureIfNotNull(MACHINE_LOCATION_CUSTOMIZERS, machineCustomizers.size() > 0 ? machineCustomizers : null);
        return getManagementContext().getLocationManager().createLocation(spec);
    } else {
        throw new UnsupportedOperationException("Cannot create WinRmMachineLocation because " + this + " is not managed");
    }
}
 
Example 20
Source File: JmxSupport.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/** applies _some_ of the common settings needed to connect via JMX */
public void applyJmxJavaSystemProperties(MutableMap.Builder<String,Object> result) {
    if (!isJmx()) return ;

    Integer jmxPort = Preconditions.checkNotNull(entity.getAttribute(JMX_PORT), "jmx port must not be null for %s", entity);
    HostAndPort jmx = BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, jmxPort);
    Integer jmxRemotePort = getEntity().getAttribute(JMX_PORT);
    String hostName = jmx.getHostText();

    result.put("com.sun.management.jmxremote", null);
    result.put("java.rmi.server.hostname", hostName);

    switch (getJmxAgentMode()) {
    case JMXMP_AND_RMI:
        Integer rmiRegistryPort = Preconditions.checkNotNull(entity.getAttribute(UsesJmx.RMI_REGISTRY_PORT), "registry port (config val %s)", entity.getConfig(UsesJmx.RMI_REGISTRY_PORT));
        result.put(JmxmpAgent.RMI_REGISTRY_PORT_PROPERTY, rmiRegistryPort);
    case JMXMP:
        if (jmxRemotePort==null || jmxRemotePort<=0)
            throw new IllegalStateException("Unsupported JMX port "+jmxRemotePort+" - when applying system properties ("+getJmxAgentMode()+" / "+getEntity()+")");
        result.put(JmxmpAgent.JMXMP_PORT_PROPERTY, jmxRemotePort);
        // with JMXMP don't try to tell it the hostname -- it isn't needed for JMXMP, and if specified
        // it will break if the hostname we see is not known at the server, e.g. a forwarding public IP
        result.remove("java.rmi.server.hostname");
        break;
    case JMX_RMI_CUSTOM_AGENT:
        if (jmxRemotePort==null || jmxRemotePort<=0)
            throw new IllegalStateException("Unsupported JMX port "+jmxRemotePort+" - when applying system properties ("+getJmxAgentMode()+" / "+getEntity()+")");
        result.put(JmxRmiAgent.RMI_REGISTRY_PORT_PROPERTY, Preconditions.checkNotNull(entity.getAttribute(UsesJmx.RMI_REGISTRY_PORT), "registry port"));
        result.put(JmxRmiAgent.JMX_SERVER_PORT_PROPERTY, jmxRemotePort);
        break;
    case NONE:
        jmxRemotePort = fixPortsForModeNone();
    case JMX_RMI:
        result.put("com.sun.management.jmxremote.port", jmxRemotePort);
        result.put("java.rmi.server.useLocalHostname", "true");
        break;
    default:
        throw new IllegalStateException("Unsupported JMX mode - when applying system properties ("+getJmxAgentMode()+" / "+getEntity()+")");
    }

    if (isSecure()) {
        // set values true, and apply keys pointing to keystore / truststore
        getJmxSslSupport().applyAgentJmxJavaSystemProperties(result);
    } else {
        result.
            put("com.sun.management.jmxremote.ssl", false).
            put("com.sun.management.jmxremote.authenticate", false);
    }
}