Search in sources :

Example 1 with ServiceLocatorTracker

use of org.talend.esb.locator.tracker.ServiceLocatorTracker in project tesb-rt-se by Talend.

the class ListOperation method execute.

@Override
public Object execute() throws Exception {
    ServiceLocatorTracker slt = ServiceLocatorTracker.getInstance(sl);
    slt.updateServiceList();
    try {
        List<QName> services = new ArrayList<QName>(slt.getServiceQNames());
        if (services.isEmpty()) {
            System.out.println();
            System.out.println("No Services registered at Service Locator");
            System.out.println();
            return null;
        }
        sortServices(services);
        for (QName service : services) {
            if (filter != null && filter.length() > 0 && !service.toString().contains(filter)) {
                // Filter is set but does not match
                continue;
            }
            StringBuilder sb = new StringBuilder();
            List<SLEndpoint> endpoints = sl.getEndpoints(service);
            sortEndpoints(endpoints);
            int offlineEndpointsCount = 0;
            int onlineEndpointsCount = 0;
            for (SLEndpoint endpoint : endpoints) {
                boolean alive = endpoint.isLive();
                if (alive) {
                    onlineEndpointsCount++;
                } else {
                    offlineEndpointsCount++;
                }
                if (!offlineEndpointsOnly || offlineEndpointsOnly && !alive) {
                    sb.append(" |-");
                    sb.append(alive ? "\u001b[1;32m online \u001b[0m : " : "\u001b[1;31m offline\u001b[0m : ");
                    String address = endpoint.getAddress();
                    sb.append(address);
                    if (printProtocol || verbose) {
                        String protocol = endpoint.getBinding().getValue();
                        sb.append(" : ").append(protocol);
                    }
                    if (printTransport || verbose) {
                        String transport = endpoint.getTransport().getValue();
                        sb.append(" : ").append(transport);
                    }
                    if (printDate || verbose) {
                        if (alive) {
                            long lastTimeStarted = endpoint.getLastTimeStarted();
                            sb.append(" : online since ").append(formatTimeStamp(lastTimeStarted));
                        } else {
                            long lastTimeStopped = endpoint.getLastTimeStopped();
                            sb.append(" : offline since ").append(formatTimeStamp(lastTimeStopped));
                        }
                    }
                    sb.append("\n");
                    if (printProperties || verbose) {
                        sb.append(printProperties(endpoint.getProperties()));
                    }
                }
            }
            // Now add first line including endpoint count
            StringBuilder sbServiceName = new StringBuilder();
            if (printServiceNamespace || verbose) {
                sbServiceName.append("{").append(service.getNamespaceURI()).append("}");
            }
            sbServiceName.append("\u001b[1;37m").append(service.getLocalPart()).append("\u001b[0m");
            sbServiceName.append(" (").append(onlineEndpointsCount).append("/").append(onlineEndpointsCount + offlineEndpointsCount).append(")");
            sbServiceName.append("\n");
            sb.insert(0, sbServiceName);
            // Now print complete StringBuilder content
            if (// No offline filter applied
            !offlineServicesOnly && !offlineEndpointsOnly || // Only services with no active endpoint
            offlineServicesOnly && onlineEndpointsCount == 0 || // Only offline endpoints
            offlineEndpointsOnly && !offlineServicesOnly && offlineEndpointsCount > 0) {
                System.out.println();
                System.out.println(sb);
            }
        }
    } catch (ServiceLocatorException e) {
        System.err.println(e.getMessage());
    }
    System.out.println();
    return null;
}
Also used : QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) ServiceLocatorTracker(org.talend.esb.locator.tracker.ServiceLocatorTracker) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint)

Example 2 with ServiceLocatorTracker

use of org.talend.esb.locator.tracker.ServiceLocatorTracker in project tesb-rt-se by Talend.

the class RegisterOperation method execute.

@Override
public Object execute() throws Exception {
    ServiceLocatorTracker slt = ServiceLocatorTracker.getInstance(sl);
    System.out.println();
    try {
        QName serviceName = slt.getServiceName(service);
        sl.register(serviceName, endpoint, persistent);
        System.out.println("Endpoint has been registered at Service Locator");
        slt.updateServiceList();
    } catch (ServiceLocatorException e) {
        System.err.println(e.getMessage());
    }
    System.out.println();
    return null;
}
Also used : QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) ServiceLocatorTracker(org.talend.esb.locator.tracker.ServiceLocatorTracker)

Example 3 with ServiceLocatorTracker

use of org.talend.esb.locator.tracker.ServiceLocatorTracker in project tesb-rt-se by Talend.

the class EndpointAddressCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> list) {
    ServiceLocatorTracker slt = ServiceLocatorTracker.getInstance(sl);
    String[] arguments = commandLine.getArguments();
    int paramCount = 0;
    for (String arg : arguments) {
        if (arg.startsWith("-")) {
            paramCount++;
        }
    }
    StringsCompleter delegate2 = new StringsCompleter();
    delegate2.getStrings().addAll(slt.getEndpoints(arguments[(arguments.length - paramCount > 2) ? arguments.length - 2 : arguments.length - 1]));
    return delegate2.complete(session, commandLine, list);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ServiceLocatorTracker(org.talend.esb.locator.tracker.ServiceLocatorTracker)

Example 4 with ServiceLocatorTracker

use of org.talend.esb.locator.tracker.ServiceLocatorTracker in project tesb-rt-se by Talend.

the class RemoveOperation method execute.

@Override
public Object execute() throws Exception {
    ServiceLocatorTracker slt = ServiceLocatorTracker.getInstance(sl);
    System.out.println();
    try {
        QName serviceName = slt.getServiceName(service);
        sl.removeEndpoint(serviceName, endpoint);
        System.out.println("Endpoint has been removed from Service Locator");
        slt.updateServiceList();
    } catch (ServiceLocatorException e) {
        System.err.println(e.getMessage());
    }
    System.out.println();
    return null;
}
Also used : QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) ServiceLocatorTracker(org.talend.esb.locator.tracker.ServiceLocatorTracker)

Example 5 with ServiceLocatorTracker

use of org.talend.esb.locator.tracker.ServiceLocatorTracker in project tesb-rt-se by Talend.

the class UnregisterOperation method execute.

@Override
public Object execute() throws Exception {
    ServiceLocatorTracker slt = ServiceLocatorTracker.getInstance(sl);
    System.out.println();
    try {
        QName serviceName = slt.getServiceName(service);
        sl.unregister(serviceName, endpoint);
        System.out.println("Endpoint has been unregistered at Service Locator");
    } catch (ServiceLocatorException e) {
        System.err.println(e.getMessage());
    }
    System.out.println();
    return null;
}
Also used : QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) ServiceLocatorTracker(org.talend.esb.locator.tracker.ServiceLocatorTracker)

Aggregations

ServiceLocatorTracker (org.talend.esb.locator.tracker.ServiceLocatorTracker)5 QName (javax.xml.namespace.QName)4 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)4 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)1 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)1