Search in sources :

Example 1 with SLEndpoint

use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.

the class LocatorSoapServiceImpl method buildEndpoint.

/**
 * Build Endpoint Reference for giving service name and address
 *
 * @param serviceName
 * @param adress
 * @return
 */
private W3CEndpointReference buildEndpoint(QName serviceName, String adress) throws ServiceLocatorFault, InterruptedExceptionFault {
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    // builder.serviceName(serviceName);
    builder.address(adress);
    SLEndpoint endpoint = null;
    try {
        endpoint = locatorClient.getEndpoint(serviceName, adress);
    } catch (ServiceLocatorException e) {
        ServiceLocatorFaultDetail serviceFaultDetail = new ServiceLocatorFaultDetail();
        serviceFaultDetail.setLocatorFaultDetail(serviceName.toString() + "throws ServiceLocatorFault");
        throw new ServiceLocatorFault(e.getMessage(), serviceFaultDetail);
    } catch (InterruptedException e) {
        InterruptionFaultDetail interruptionFaultDetail = new InterruptionFaultDetail();
        interruptionFaultDetail.setInterruptionDetail(serviceName.toString() + "throws InterruptionFault");
        throw new InterruptedExceptionFault(e.getMessage(), interruptionFaultDetail);
    }
    if (endpoint != null) {
        SLProperties properties = endpoint.getProperties();
        if (properties != null && !properties.getPropertyNames().isEmpty()) {
            EndpointTransformerImpl transformer = new EndpointTransformerImpl();
            DOMResult result = new DOMResult();
            transformer.writePropertiesTo(properties, result);
            Document docResult = (Document) result.getNode();
            builder.metadata(docResult.getDocumentElement());
        }
    }
    return builder.build();
}
Also used : SLProperties(org.talend.esb.servicelocator.client.SLProperties) W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) EndpointTransformerImpl(org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl) DOMResult(javax.xml.transform.dom.DOMResult) InterruptionFaultDetail(org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) ServiceLocatorFault(org.talend.services.esb.locator.v1.ServiceLocatorFault) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Document(org.w3c.dom.Document) InterruptedExceptionFault(org.talend.services.esb.locator.v1.InterruptedExceptionFault) ServiceLocatorFaultDetail(org.talend.schemas.esb.locator._2011._11.ServiceLocatorFaultDetail)

Example 2 with SLEndpoint

use of org.talend.esb.servicelocator.client.SLEndpoint 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 3 with SLEndpoint

use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.

the class LocatorMonitor method startScanning.

private void startScanning() {
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    scheduler.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            MDC.put(EVENT_CATEGORY, MONITORING);
            try {
                if (sl != null) {
                    List<QName> services = sl.getServices();
                    int activeService = 0;
                    int totalActiveEndpoints = 0;
                    int totalOfflineEndpoints = 0;
                    for (QName service : services) {
                        List<SLEndpoint> endpoints = sl.getEndpoints(service);
                        int activeEndpoints = 0;
                        MDC.put(SERVICE_QNAME, service);
                        for (SLEndpoint endpoint : endpoints) {
                            boolean alive = endpoint.isLive();
                            MDC.put(ACTIVE, alive);
                            String address = endpoint.getAddress();
                            MDC.put(ADDRESS, address);
                            String protocol = endpoint.getBinding().getValue();
                            MDC.put(PROTOCOL, protocol);
                            String transport = endpoint.getTransport().getValue();
                            MDC.put(TRANSPORT, transport);
                            long lastTimeStarted = endpoint.getLastTimeStarted();
                            MDC.put(LAST_TIME_STARTED, formatTimeStamp(lastTimeStarted));
                            long lastTimeStopped = endpoint.getLastTimeStopped();
                            MDC.put(LAST_TIME_STOPPED, formatTimeStamp(lastTimeStopped));
                            String[] mdcPropertyKeys = addPropertiesToMDC(endpoint.getProperties());
                            if (alive) {
                                activeEndpoints++;
                                totalActiveEndpoints++;
                                LOG.info(ENDPOINT_INFO, "Endpoint for Service {} with Address {} is alive since {}", service, address, formatTimeStamp(lastTimeStarted));
                            } else {
                                LOG.warn(ENDPOINT_INFO, "Endpoint for Service {} with Address {} is down since {}", service, address, formatTimeStamp(lastTimeStopped));
                                totalOfflineEndpoints++;
                            }
                            cleanMDC(mdcPropertyKeys);
                            cleanMDC(ACTIVE, ADDRESS, PROTOCOL, TRANSPORT, LAST_TIME_STARTED, LAST_TIME_STOPPED);
                        }
                        MDC.remove(ACTIVE);
                        MDC.put(COUNT, endpoints.size());
                        LOG.info(SERVICE_INFO, "{} endpoints are registered for service {}", endpoints.size(), service);
                        MDC.put(ACTIVE, true);
                        MDC.put(COUNT, activeEndpoints);
                        LOG.info(SERVICE_INFO, "{} endpoints are active for service {}", activeEndpoints, service);
                        MDC.put(ACTIVE, false);
                        int offlineEndpoints = endpoints.size() - activeEndpoints;
                        MDC.put(COUNT, offlineEndpoints);
                        if (offlineEndpoints > 0) {
                            LOG.warn(SERVICE_INFO, "{} endpoints are offline for service {}", offlineEndpoints, service);
                        } else {
                            LOG.info(SERVICE_INFO, "{} endpoints are offline for service {}", offlineEndpoints, service);
                        }
                        if (activeEndpoints > 0) {
                            activeService++;
                        }
                        cleanMDC(COUNT, ACTIVE, SERVICE_QNAME);
                    }
                    // Absolute Numbers for Services
                    MDC.put(COUNT, services.size());
                    MDC.remove(ACTIVE);
                    LOG.info(SERVICES, "{} services are registered at the ServiceLocator", services.size());
                    MDC.put(COUNT, activeService);
                    MDC.put(ACTIVE, true);
                    LOG.info(SERVICES, "{} services are available and currently registered at the ServiceLocator", activeService);
                    MDC.put(COUNT, services.size() - activeService);
                    MDC.put(ACTIVE, false);
                    LOG.info(SERVICES, "{} services are currently registered at the ServiceLocator but are not available", services.size() - activeService);
                    // Absolute Numbers for Endpoints
                    MDC.put(COUNT, totalActiveEndpoints + totalOfflineEndpoints);
                    MDC.remove(ACTIVE);
                    LOG.info(ENDPOINTS, "{} endpoints are registered at the ServiceLocator", totalActiveEndpoints + totalOfflineEndpoints);
                    MDC.put(COUNT, totalActiveEndpoints);
                    MDC.put(ACTIVE, true);
                    LOG.info(ENDPOINTS, "{} endpoints are available and currently registered at the ServiceLocator", totalActiveEndpoints);
                    MDC.put(COUNT, totalOfflineEndpoints);
                    MDC.put(ACTIVE, false);
                    LOG.info(ENDPOINTS, "{} endpoints are currently registered at the ServiceLocator but are not available", totalOfflineEndpoints);
                    cleanMDC(COUNT, ACTIVE);
                }
            } catch (ServiceLocatorException e) {
                LOG.warn("Error during SL monitoring", e);
            } catch (InterruptedException e) {
            }
            MDC.remove(EVENT_CATEGORY);
        }
    }, startDelay, scanIntervall, TimeUnit.SECONDS);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) List(java.util.List) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint)

Example 4 with SLEndpoint

use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.

the class ServiceLocatorImpl method getEndpoints.

/**
 * {@inheritDoc}
 */
@Override
public synchronized List<SLEndpoint> getEndpoints(final QName serviceName) throws ServiceLocatorException, InterruptedException {
    RootNode rootNode = getBackend().connect();
    ServiceNode serviceNode = rootNode.getServiceNode(serviceName);
    if (serviceNode.exists()) {
        List<EndpointNode> endpointNodes = serviceNode.getEndPoints();
        List<SLEndpoint> slEndpoints = new ArrayList<SLEndpoint>(endpointNodes.size());
        for (EndpointNode endpointNode : endpointNodes) {
            byte[] content = endpointNode.getContent();
            final boolean isLive = endpointNode.isLive();
            SLEndpoint slEndpoint = transformer.toSLEndpoint(serviceName, content, isLive);
            slEndpoints.add(slEndpoint);
        }
        return slEndpoints;
    } else {
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint)

Example 5 with SLEndpoint

use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.

the class GetEndpointsTest method getEndpointsEndpointIsNotLive.

@Test
public void getEndpointsEndpointIsNotLive() throws Exception {
    expect(backend.connect()).andReturn(rootNode);
    expect(rootNode.getServiceNode(SERVICE_QNAME_1)).andReturn(serviceNode);
    expect(serviceNode.exists()).andReturn(true);
    expect(serviceNode.getEndPoints()).andReturn(Arrays.asList(endpointNode));
    expect(endpointNode.isLive()).andReturn(false);
    expect(endpointNode.getContent()).andReturn(CONTENT_ENDPOINT_1);
    replayAll();
    ServiceLocatorImpl slc = new ServiceLocatorImpl();
    slc.setBackend(backend);
    List<SLEndpoint> endpoints = slc.getEndpoints(SERVICE_QNAME_1);
    SLEndpoint endpoint = endpoints.get(0);
    assertFalse(endpoint.isLive());
    verifyAll();
}
Also used : SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Test(org.junit.Test)

Aggregations

SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)13 QName (javax.xml.namespace.QName)5 Test (org.junit.Test)5 SLProperties (org.talend.esb.servicelocator.client.SLProperties)4 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)4 DOMResult (javax.xml.transform.dom.DOMResult)2 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)2 EndpointTransformerImpl (org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl)2 Document (org.w3c.dom.Document)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Bus (org.apache.cxf.Bus)1 ClientLifeCycleManagerImpl (org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl)1 ServerLifeCycleManagerImpl (org.apache.cxf.bus.managers.ServerLifeCycleManagerImpl)1 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)1 Service (org.apache.cxf.service.Service)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1