Search in sources :

Example 41 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class FabricGitSummaryAction method beforeEachContainer.

@Override
protected void beforeEachContainer(Collection<String> names) throws Exception {
    // first, we need summary from fabric-git-server (to have something to compare local git repositories to)
    master = fabricService.getGitMaster();
    if (master == null) {
        System.out.println("Can't find container which is current git master");
        return;
    }
    System.out.println("Git master is: " + master);
    // ask master about the status first
    String queuePath = ZkPath.COMMANDS_REQUESTS_QUEUE.getPath(master);
    masterRequest = new JMXRequest().withObjectName("io.fabric8:type=GitServer").withMethod("gitVersions");
    String command = map(masterRequest);
    curator.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(queuePath, PublicStringSerializer.serialize(command));
}
Also used : JMXRequest(io.fabric8.api.commands.JMXRequest)

Example 42 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class ContainerInfoAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    containerName = Strings.isNotBlank(containerName) ? containerName : runtimeProperties.getRuntimeIdentity();
    validateContainerName(containerName);
    if (!containerExists(containerName)) {
        System.out.println("Container " + containerName + " does not exists!");
        return 1;
    }
    Container container = fabricService.getContainer(containerName);
    System.out.println(String.format(FORMAT, "Name:", container.getId()));
    System.out.println(String.format(FORMAT, "Version:", container.getVersionId()));
    System.out.println(String.format(FORMAT, "Connected:", container.isAlive()));
    System.out.println(String.format(FORMAT, "Type:", emptyIfNull(container.getType())));
    System.out.println(String.format(FORMAT, "Root:", container.isRoot()));
    System.out.println(String.format(FORMAT, "Ensemble Server:", container.isEnsembleServer()));
    System.out.println(String.format(FORMAT, "Managed:", container.isManaged()));
    Long processId = container.getProcessId();
    System.out.println(String.format(FORMAT, "Process ID:", ((processId != null) ? processId.toString() : "")));
    if (Strings.isNotBlank(container.getLocation())) {
        System.out.println(String.format(FORMAT, "Location:", emptyIfNull(container.getLocation())));
    }
    System.out.println(String.format(FORMAT, "Resolver:", emptyIfNull(container.getResolver())));
    System.out.println(String.format(FORMAT, "Network Address:", emptyIfNull(container.getIp())));
    System.out.println(String.format(FORMAT, "Local Network Address:", emptyIfNull(container.getLocalIp())));
    System.out.println(String.format(FORMAT, "Public Network Address:", emptyIfNull(container.getPublicIp())));
    System.out.println(String.format(FORMAT, "Local Hostname:", emptyIfNull(container.getLocalHostname())));
    System.out.println(String.format(FORMAT, "Public Hostname:", emptyIfNull(container.getPublicHostname())));
    System.out.println(String.format(FORMAT, "SSH Url:", emptyIfNull(container.getSshUrl())));
    System.out.println(String.format(FORMAT, "JMX Url:", emptyIfNull(container.getJmxUrl())));
    System.out.println(String.format(FORMAT, "Http Url:", emptyIfNull(container.getHttpUrl())));
    System.out.println(String.format(FORMAT, "Jolokia Url:", emptyIfNull(container.getJolokiaUrl())));
    String debugPort = container.getDebugPort();
    if (Strings.isNotBlank(debugPort)) {
        System.out.println(String.format(FORMAT, "Debug Port:", debugPort));
    }
    if (verbose != null && verbose) {
        // we want each profile on a separate line
        Profile[] profiles = container.getProfiles();
        for (int i = 0; i < profiles.length; i++) {
            String id = profiles[i].getId();
            if (i == 0) {
                System.out.println(String.format(FORMAT, "Profiles:", id));
            } else {
                System.out.println(String.format(FORMAT, "", id));
            }
        }
        Container parent = container.getParent();
        if (parent != null) {
            System.out.println(String.format(FORMAT, "Parent:", parent.getId()));
        }
        // we want each child on a separate line
        Container[] children = container.getChildren();
        for (int i = 0; i < children.length; i++) {
            String id = children[i].getId();
            if (i == 0) {
                System.out.println(String.format(FORMAT, "Children:", id));
            } else {
                System.out.println(String.format(FORMAT, "", id));
            }
        }
    }
    String blueprintStatus = dataStore.getContainerAttribute(containerName, DataStore.ContainerAttribute.BlueprintStatus, "", false, false);
    String springStatus = dataStore.getContainerAttribute(containerName, DataStore.ContainerAttribute.SpringStatus, "", false, false);
    if (!blueprintStatus.isEmpty()) {
        System.out.println(String.format(FORMAT, "Blueprint Status:", blueprintStatus.toLowerCase()));
    }
    if (!springStatus.isEmpty()) {
        System.out.println(String.format(FORMAT, "Spring Status:", springStatus.toLowerCase()));
    }
    System.out.println(String.format(FORMAT, "Provision Status:", container.getProvisionStatus()));
    if (container.getProvisionException() != null) {
        System.out.println(String.format(FORMAT, "Provision Error:", container.getProvisionException()));
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) Profile(io.fabric8.api.Profile)

Example 43 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class InvocationTest method testUnderLoadSyncObject.

@Test(timeout = 30 * 1000)
public void testUnderLoadSyncObject() throws Exception {
    HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
    DispatchQueue queue = Dispatch.createQueue();
    ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
    server.start();
    ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
    client.start();
    try {
        final HelloImpl helloImpl = new HelloImpl();
        server.registerService("service-id", new ServerInvoker.ServiceFactory() {

            public Object get() {
                return helloImpl;
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        final Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        assertEquals("Hello World!", hello.helloworld());
        final AtomicInteger requests = new AtomicInteger(0);
        final AtomicInteger failures = new AtomicInteger(0);
        final long[] latencies = new long[BENCHMARK_CLIENTS * BENCHMARK_INVOCATIONS_PER_CLIENT];
        final long start = System.nanoTime();
        Thread[] threads = new Thread[BENCHMARK_CLIENTS];
        for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
            final int thread_idx = t;
            threads[t] = new Thread() {

                public void run() {
                    for (int i = 0; i < BENCHMARK_INVOCATIONS_PER_CLIENT; i++) {
                        try {
                            requests.incrementAndGet();
                            String response;
                            final long start = System.nanoTime();
                            response = hello.hello("Fabric");
                            final long end = System.nanoTime();
                            latencies[(thread_idx * BENCHMARK_INVOCATIONS_PER_CLIENT) + i] = end - start;
                            assertEquals("Hello Fabric!", response);
                        } catch (Throwable t) {
                            latencies[(thread_idx * BENCHMARK_INVOCATIONS_PER_CLIENT) + i] = -1;
                            failures.incrementAndGet();
                            if (t instanceof UndeclaredThrowableException) {
                                t = ((UndeclaredThrowableException) t).getUndeclaredThrowable();
                            }
                            System.err.println("Error: " + t.getClass().getName() + (t.getMessage() != null ? " (" + t.getMessage() + ")" : ""));
                        }
                    }
                }
            };
            threads[t].start();
        }
        for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
            threads[t].join();
        }
        final long end = System.nanoTime();
        long latency_sum = 0;
        for (int t = 0; t < latencies.length; t++) {
            if (latencies[t] != -1) {
                latency_sum += latencies[t];
            }
        }
        double latency_avg = ((latency_sum * 1.0d) / requests.get()) / MILLIS_IN_A_NANO;
        double request_rate = ((requests.get() * 1.0d) / (end - start)) * SECONDS_IN_A_NANO;
        System.err.println(String.format("Requests/Second: %,.2f", request_rate));
        System.err.println(String.format("Average request latency: %,.2f ms", latency_avg));
        System.err.println("Error Ratio: " + failures.get() + " / " + requests.get());
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 44 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class InvocationTest method testNoOverflow.

@Test(timeout = 30 * 1000)
public void testNoOverflow() throws Exception {
    DispatchQueue queue = Dispatch.createQueue();
    HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
    map.put("protobuf", new ProtobufSerializationStrategy());
    ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
    server.start();
    ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
    client.start();
    try {
        server.registerService("service-id", new ServerInvoker.ServiceFactory() {

            public Object get() {
                return new HelloImpl();
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        char[] chars = new char[65 * 1024];
        String payload = new String(chars);
        for (int i = 0; i < 100; i++) {
            hello.hello(payload);
        }
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 45 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class TransportFailureTest method testInvoke.

@Test
public void testInvoke() throws Exception {
    DispatchQueue queue = Dispatch.createQueue();
    HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
    map.put("protobuf", new ProtobufSerializationStrategy());
    ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
    server.start();
    ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
    client.start();
    try {
        server.registerService("service-id", new ServerInvoker.ServiceFactory() {

            public Object get() {
                return new HelloImpl();
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        AsyncCallbackFuture<String> future1 = new AsyncCallbackFuture<String>();
        hello.hello("Guillaume", future1);
        long t0 = System.currentTimeMillis();
        try {
            assertEquals("Hello Guillaume!", future1.get(MAX_DELAY, TimeUnit.MILLISECONDS));
            fail("Should have thrown an exception");
        } catch (Exception e) {
            // Expected
            long t1 = System.currentTimeMillis();
            assertTrue(t1 - t0 > SLEEP_TIME / 2);
            assertTrue(t1 - t0 < MAX_DELAY / 2);
        }
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) AsyncCallbackFuture(io.fabric8.dosgi.api.AsyncCallbackFuture) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ProtobufSerializationStrategy(io.fabric8.dosgi.api.ProtobufSerializationStrategy) SerializationStrategy(io.fabric8.dosgi.api.SerializationStrategy) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) ProtobufSerializationStrategy(io.fabric8.dosgi.api.ProtobufSerializationStrategy) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)20 Test (org.junit.Test)19 IOException (java.io.IOException)18 File (java.io.File)9 Map (java.util.Map)9 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 ArrayList (java.util.ArrayList)8 Profile (io.fabric8.api.Profile)7 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 DispatchQueue (org.fusesource.hawtdispatch.DispatchQueue)7 Container (io.fabric8.api.Container)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 Version (io.fabric8.api.Version)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 FabricException (io.fabric8.api.FabricException)4 RuntimeProperties (io.fabric8.api.RuntimeProperties)4 InputStream (java.io.InputStream)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3