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