Search in sources :

Example 11 with ServiceLocatorException

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

the class ServiceLocatorTracker method updateServiceList.

public void updateServiceList() {
    try {
        List<QName> services = sl.getServices();
        synchronized (this) {
            serviceMap.clear();
            endpointMap.clear();
            for (QName service : services) {
                serviceMap.put(service.getLocalPart(), service);
                endpointMap.put(service.toString(), sl.getEndpointNames(service));
            }
        }
    } catch (InterruptedException e) {
    } catch (ServiceLocatorException e) {
        LOG.warn(e.getMessage());
    }
}
Also used : QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException)

Example 12 with ServiceLocatorException

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

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

the class LocatorSoapServiceImpl method lookupEndpoint.

/**
 * For the given service return endpoint reference randomly selected from
 * list of endpoints currently registered at the service locator server.
 *
 * @param serviceName
 *            the name of the service for which to get the endpoints, must
 *            not be <code>null</code>
 * @return endpoint references or <code>null</code>
 */
W3CEndpointReference lookupEndpoint(QName serviceName, MatcherDataType matcherData) throws ServiceLocatorFault, InterruptedExceptionFault {
    List<String> names = null;
    String adress;
    try {
        initLocator();
        SLPropertiesMatcher matcher = createMatcher(matcherData);
        if (matcher == null) {
            names = locatorClient.lookup(serviceName);
        } else {
            names = locatorClient.lookup(serviceName, matcher);
        }
    } 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 (names != null && !names.isEmpty()) {
        names = getRotatedList(names);
        adress = names.get(0);
    } else {
        if (LOG.isLoggable(Level.WARNING)) {
            LOG.log(Level.WARNING, "lookup Endpoint for " + serviceName + " failed, service is not known.");
        }
        ServiceLocatorFaultDetail serviceFaultDetail = new ServiceLocatorFaultDetail();
        serviceFaultDetail.setLocatorFaultDetail("lookup Endpoint for " + serviceName + " failed, service is not known.");
        throw new ServiceLocatorFault("Can not find Endpoint", serviceFaultDetail);
    }
    return buildEndpoint(serviceName, adress);
}
Also used : InterruptionFaultDetail(org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) SLPropertiesMatcher(org.talend.esb.servicelocator.client.SLPropertiesMatcher) ServiceLocatorFault(org.talend.services.esb.locator.v1.ServiceLocatorFault) InterruptedExceptionFault(org.talend.services.esb.locator.v1.InterruptedExceptionFault) ServiceLocatorFaultDetail(org.talend.schemas.esb.locator._2011._11.ServiceLocatorFaultDetail)

Example 14 with ServiceLocatorException

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

the class LocatorSoapServiceTest method unregisterEndpointExpectedLocatorException.

@Test(expected = ServiceLocatorFault.class)
public void unregisterEndpointExpectedLocatorException() throws ServiceLocatorException, InterruptedException, ServiceLocatorFault, InterruptedExceptionFault {
    sl.unregister(SERVICE_NAME, ENDPOINTURL);
    EasyMock.expectLastCall().andStubThrow(new ServiceLocatorException("test"));
    replayAll();
    lps.unregisterEndpoint(SERVICE_NAME, ENDPOINTURL);
}
Also used : ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) Test(org.junit.Test)

Example 15 with ServiceLocatorException

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

the class ServiceLocatorImplTest method removeEndpointFails.

@Test
public void removeEndpointFails() throws Exception {
    expect(backend.connect()).andReturn(rootNode);
    expect(rootNode.getServiceNode(SERVICE_QNAME_1)).andReturn(serviceNode);
    expect(serviceNode.getEndPoint(ENDPOINT_1)).andReturn(endpointNode);
    endpointNode.ensureRemoved();
    expectLastCall().andThrow(new ServiceLocatorException());
    replayAll();
    ServiceLocatorImpl slc = new ServiceLocatorImpl();
    slc.setBackend(backend);
    try {
        slc.removeEndpoint(SERVICE_QNAME_1, ENDPOINT_1);
        fail("A ServiceLocatorException should have been thrown.");
    } catch (ServiceLocatorException e) {
        ignore("Expected exception");
    }
    verifyAll();
}
Also used : ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) Test(org.junit.Test)

Aggregations

ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)35 Test (org.junit.Test)13 QName (javax.xml.namespace.QName)11 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)8 WebApplicationException (javax.ws.rs.WebApplicationException)6 InterruptionFaultDetail (org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail)6 ServiceLocatorFaultDetail (org.talend.schemas.esb.locator._2011._11.ServiceLocatorFaultDetail)6 InterruptedExceptionFault (org.talend.services.esb.locator.v1.InterruptedExceptionFault)6 ServiceLocatorFault (org.talend.services.esb.locator.v1.ServiceLocatorFault)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ServiceLocatorTracker (org.talend.esb.locator.tracker.ServiceLocatorTracker)4 SLPropertiesMatcher (org.talend.esb.servicelocator.client.SLPropertiesMatcher)4 SimpleEndpoint (org.talend.esb.servicelocator.client.SimpleEndpoint)4 JAXBException (javax.xml.bind.JAXBException)3 Endpoint (org.talend.esb.servicelocator.client.Endpoint)3 DOMResult (javax.xml.transform.dom.DOMResult)2 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)2 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)2 BindingType (org.talend.esb.servicelocator.client.BindingType)2 SLProperties (org.talend.esb.servicelocator.client.SLProperties)2