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());
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations