Search in sources :

Example 51 with Service

use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.

the class InvocationTest method testInvoke.

@Test(timeout = 30 * 1000)
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);
        assertEquals("Hello Fabric!", hello.hello("Fabric"));
        assertEquals("Hello World!", hello.helloworld());
        // Verification the we can pick the right overloaded method even if using a mixure
        // of primitives / objects and array dimensions.
        assertEquals('a', hello.mix(0));
        assertEquals('b', hello.mix(new int[] { 0 }));
        assertEquals('c', hello.mix(new Integer(0)));
        assertEquals('d', hello.mix(new Integer[] { new Integer(0) }));
        assertEquals('e', hello.mix(new int[0][0]));
        assertEquals('f', hello.mix(new Integer[0][0]));
        AsyncCallbackFuture<String> future1 = new AsyncCallbackFuture<String>();
        hello.hello("Hiram", future1);
        assertEquals("Hello Hiram!", future1.get(2, TimeUnit.SECONDS));
        assertEquals("Hello Hiram!", hello.protobuf(stringValue("Hiram")).getValue());
        AsyncCallbackFuture<StringValue.Getter> future2 = new AsyncCallbackFuture<StringValue.Getter>();
        hello.protobuf(stringValue("Hiram Async"), future2);
        assertEquals("Hello Hiram Async!", future2.get(2, TimeUnit.SECONDS).getValue());
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 52 with Service

use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.

the class ServerInvokerImpl method onCommand.

protected void onCommand(final Transport transport, Object data) {
    try {
        final DataByteArrayInputStream bais = new DataByteArrayInputStream((Buffer) data);
        final int size = bais.readInt();
        final long correlation = bais.readVarLong();
        // Use UTF8Buffer instead of string to avoid encoding/decoding UTF-8 strings
        // for every request.
        final UTF8Buffer service = readBuffer(bais).utf8();
        final Buffer encoded_method = readBuffer(bais);
        final ServiceFactoryHolder holder = holders.get(service);
        final MethodData methodData = holder.getMethodData(encoded_method);
        final Object svc = holder.factory.get();
        Runnable task = new Runnable() {

            public void run() {
                final DataByteArrayOutputStream baos = new DataByteArrayOutputStream();
                try {
                    // make space for the size field.
                    baos.writeInt(0);
                    baos.writeVarLong(correlation);
                } catch (IOException e) {
                    // should not happen
                    throw new RuntimeException(e);
                }
                // Lets decode the remaining args on the target's executor
                // to take cpu load off the
                methodData.invocationStrategy.service(methodData.serializationStrategy, holder.loader, methodData.method, svc, bais, baos, new Runnable() {

                    public void run() {
                        holder.factory.unget();
                        final Buffer command = baos.toBuffer();
                        // Update the size field.
                        BufferEditor editor = command.buffer().bigEndianEditor();
                        editor.writeInt(command.length);
                        queue().execute(new Runnable() {

                            public void run() {
                                transport.offer(command);
                            }
                        });
                    }
                });
            }
        };
        Executor executor;
        if (svc instanceof Dispatched) {
            executor = ((Dispatched) svc).queue();
        } else {
            executor = blockingExecutor;
        }
        executor.execute(task);
    } catch (Exception e) {
        LOGGER.info("Error while reading request", e);
    }
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) EOFException(java.io.EOFException) Dispatched(io.fabric8.dosgi.api.Dispatched) Executor(java.util.concurrent.Executor)

Example 53 with Service

use of io.fabric8.patch.Service in project jointware by isdream.

the class KubernetesKeyValueStyleGeneratorTest method testKubernetesWithAllKind.

protected static void testKubernetesWithAllKind() throws Exception {
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ServiceAccount());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ThirdPartyResource());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ResourceQuota());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Node());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ConfigMap());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new NetworkPolicy());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new CustomResourceDefinition());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Ingress());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Service());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Namespace());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Secret());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new LimitRange());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Event());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new PersistentVolume());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new StatefulSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new PersistentVolumeClaim());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new DaemonSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new HorizontalPodAutoscaler());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Pod());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ReplicaSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Job());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ReplicationController());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Deployment());
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Pod(io.fabric8.kubernetes.api.model.Pod) ThirdPartyResource(io.fabric8.kubernetes.api.model.extensions.ThirdPartyResource) NetworkPolicy(io.fabric8.kubernetes.api.model.extensions.NetworkPolicy) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition) Node(io.fabric8.kubernetes.api.model.Node) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) Namespace(io.fabric8.kubernetes.api.model.Namespace) Secret(io.fabric8.kubernetes.api.model.Secret) LimitRange(io.fabric8.kubernetes.api.model.LimitRange) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) HorizontalPodAutoscaler(io.fabric8.kubernetes.api.model.HorizontalPodAutoscaler) Event(io.fabric8.kubernetes.api.model.Event) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DaemonSet(io.fabric8.kubernetes.api.model.extensions.DaemonSet) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Job(io.fabric8.kubernetes.api.model.Job) KubernetesDocumentKeyValueStyleGenerator(com.github.isdream.chameleon.docs.KubernetesDocumentKeyValueStyleGenerator) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Example 54 with Service

use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.

the class Logs method newInstance.

public static LogEvent newInstance(PaxLoggingEvent event) {
    LogEvent answer = new LogEvent();
    try {
        answer.setLevel(toString(event.getLevel()));
    } catch (NoClassDefFoundError error) {
        // ENTESB-2234, KARAF-3350: Ignore NoClassDefFoundError exceptions
        // Those exceptions may happen if the underlying pax-logging service
        // bundle has been refreshed somehow.
        answer.setLevel("LOG");
    }
    answer.setMessage(event.getMessage());
    answer.setLogger(event.getLoggerName());
    answer.setTimestamp(new Date(event.getTimeStamp()));
    answer.setThread(event.getThreadName());
    answer.setException(addMavenCoord(event.getThrowableStrRep()));
    Map eventProperties = event.getProperties();
    if (eventProperties != null && eventProperties.size() > 0) {
        Map<String, String> properties = new HashMap<String, String>();
        Set<Map.Entry> set = eventProperties.entrySet();
        for (Map.Entry entry : set) {
            Object key = entry.getKey();
            Object value = entry.getValue();
            if (key != null && value != null) {
                properties.put(toString(key), toString(value));
            }
        }
        MavenCoordinates.addMavenCoord(properties);
        answer.setProperties(properties);
    }
    // event.getFQNOfLoggerClass()
    try {
        PaxLocationInfo locationInformation = event.getLocationInformation();
        if (locationInformation != null) {
            answer.setClassName(locationInformation.getClassName());
            answer.setFileName(locationInformation.getFileName());
            answer.setMethodName(locationInformation.getMethodName());
            answer.setLineNumber(locationInformation.getLineNumber());
        }
    } catch (NoClassDefFoundError error) {
    // ENTESB-2234, KARAF-3350: Ignore NoClassDefFoundError exceptions
    }
    return answer;
}
Also used : LogEvent(io.fabric8.insight.log.LogEvent) HashMap(java.util.HashMap) PaxLocationInfo(org.ops4j.pax.logging.spi.PaxLocationInfo) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Example 55 with Service

use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.

the class ExampleCxfProfileLongTest method testExample.

@Test
public void testExample() throws Exception {
    System.out.println("creating the cxf-server container.");
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy).withName("child").withProfiles("example-cxf-cxf.server").assertProvisioningResult().build();
        try {
            assertTrue("We should create the cxf-server container.", containers.size() == 1);
            System.out.println("created the cxf-server container.");
            // install bundle of CXF
            Thread.sleep(2000);
            System.out.println(executeCommand("fabric:cluster-list"));
            // install bundle of CXF
            Thread.sleep(2000);
            // calling the client here
            System.out.println("install the cxf client demo in root container");
            // This test need to take sometime to download the cxf feature related bundles
            System.out.println(executeCommand("features:install fabric-cxf", 600000, false));
            String projectVersion = System.getProperty("fabricitest.version");
            // install bundle of CXF demo client
            System.out.println(executeCommand("osgi:install -s mvn:io.fabric8.examples/fabric-cxf-demo-common/" + projectVersion));
            System.out.println(executeCommand("osgi:install -s mvn:io.fabric8.examples/fabric-cxf-demo-client/" + projectVersion));
            System.out.println(executeCommand("osgi:list"));
            System.out.println("invoking the web service");
            Hello proxy = ServiceLocator.awaitService(bundleContext, Hello.class);
            assertNotNull(proxy);
            String result1 = proxy.sayHello();
            String result2 = proxy.sayHello();
            assertNotSame("We should get the two different result", result1, result2);
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Hello(io.fabric8.demo.cxf.Hello) FabricService(io.fabric8.api.FabricService) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) Test(org.junit.Test)

Aggregations

Service (io.fabric8.kubernetes.api.model.Service)100 Test (org.junit.Test)78 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)35 HashMap (java.util.HashMap)33 File (java.io.File)28 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)26 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)24 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)22 Map (java.util.Map)19 Pod (io.fabric8.kubernetes.api.model.Pod)18 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)18 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)17 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)17 List (java.util.List)17 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 Reconciliation (io.strimzi.controller.cluster.Reconciliation)15 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)15 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)15