use of io.fabric8.annotations.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServices.
@Test(description = "Test .listServices() method")
public void testListServices() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Include ClusterIPs
sdKubernetes.setIncludeClusterIP(true);
// Include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(true);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceList());
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices();
Assert.assertEquals(endpoints.size(), 10);
// 2 NodePort URL endpoints
Mockito.verify(openShiftClient, Mockito.times(2)).getMasterUrl();
}
use of io.fabric8.annotations.Endpoint in project fabric8 by jboss-fuse.
the class CamelAutoTestService method onConfigured.
@Override
protected void onConfigured() throws Exception {
LOG.debug("onConfigured. mockOutputs: " + mockOutputs + " mockInputs: " + mockInputs + " messageFolder: " + messageFolder);
FabricService fabricService = this.fabricService.getOptional();
// lets find the camel contexts to test in this container
MBeanServer mbeanServerValue = mbeanServer;
if (mbeanServerValue != null && fabricService != null) {
Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile();
Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
Set<String> configurationFileNames = effectiveProfile.getConfigurationFileNames();
for (CamelContext camelContext : camelContexts.values()) {
String camelContextID = camelContext.getName();
// check we only add testing stuff to each context once
if (camelContext instanceof ModelCamelContext) {
final ModelCamelContext modelCamelContext = (ModelCamelContext) camelContext;
List<RouteDefinition> routeDefinitions = modelCamelContext.getRouteDefinitions();
if (camelContextsConfigured.add(camelContextID)) {
NodeIdFactory nodeIdFactory = camelContext.getNodeIdFactory();
if (mockInputs || mockOutputs) {
for (RouteDefinition routeDefinition : routeDefinitions) {
String routeId = routeDefinition.idOrCreate(nodeIdFactory);
modelCamelContext.stopRoute(routeId);
final String routeKey = camelContextID + "." + routeId;
LOG.info("Mocking Camel route: " + routeKey);
routeDefinition.adviceWith(modelCamelContext, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
if (mockOutputs) {
modelCamelContext.addRegisterEndpointCallback(strategy);
}
}
});
// the advised route is automatic restarted
}
}
String path = messageFolder;
if (Strings.isNotBlank(path)) {
path += "/";
}
path += camelContextID;
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
try {
for (RouteDefinition routeDefinition : routeDefinitions) {
String routeId = routeDefinition.idOrCreate(nodeIdFactory);
String routePath = path + "/" + routeId + "/";
List<FromDefinition> inputs = routeDefinition.getInputs();
for (FromDefinition input : inputs) {
Endpoint endpoint = input.getEndpoint();
if (endpoint == null) {
String uri = input.getUri();
if (Strings.isNullOrBlank(uri)) {
String ref = input.getRef();
if (Strings.isNotBlank(ref)) {
uri = "ref:" + ref;
}
}
if (Strings.isNotBlank(uri)) {
endpoint = camelContext.getEndpoint(uri);
}
}
if (endpoint == null) {
LOG.warn("Cannot find endpoint, uri or ref of input " + input + " on route " + routeId + " camelContext: " + camelContextID);
} else {
for (String configFile : configurationFileNames) {
if (configFile.startsWith(routePath)) {
LOG.info("Sending file: " + configFile + " to " + endpoint);
byte[] data = effectiveProfile.getFileConfiguration(configFile);
if (data != null) {
// lest send this message to this endpoint
producerTemplate.sendBody(endpoint, data);
}
}
}
}
}
}
} finally {
producerTemplate.stop();
}
}
}
}
}
}
use of io.fabric8.annotations.Endpoint in project fabric8 by jboss-fuse.
the class FabricWebRegistrationHandler method servletEvent.
@Override
public void servletEvent(ServletEvent servletEvent) {
if (isValid()) {
WebEvent webEvent = webEvents.get(servletEvent.getBundle());
if (webEvent != null || servletEvent.getAlias() == null) {
// this servlet is part of a web application, ignore it
return;
}
Map<String, ServletEvent> events;
synchronized (servletEvents) {
events = servletEvents.get(servletEvent.getBundle());
if (events == null) {
events = new ConcurrentHashMap<String, ServletEvent>();
servletEvents.put(servletEvent.getBundle(), events);
}
}
events.put(servletEvent.getAlias(), servletEvent);
if (curator.get().getZookeeperClient().isConnected()) {
switch(servletEvent.getType()) {
case ServletEvent.DEPLOYING:
break;
case ServletEvent.DEPLOYED:
try {
registerServlet(fabricService.get().getCurrentContainer(), servletEvent);
} catch (IllegalStateException e) {
if ("Client is not started".equals(e.getMessage())) {
LOGGER.warn("Zookeeper connection not available. Servlet endpoint might have not been registered correctly in zookeeper registry: {}", servletEvent);
}
}
break;
default:
try {
unregisterServlet(fabricService.get().getCurrentContainer(), servletEvent);
} catch (IllegalStateException e) {
if ("Client is not started".equals(e.getMessage())) {
LOGGER.warn("Zookeeper connection not available. Servlet endpoint might have not been removed correctly from zookeeper registry: {}", servletEvent);
}
}
break;
}
}
}
}
use of io.fabric8.annotations.Endpoint in project fabric8 by jboss-fuse.
the class RestJsonSchemaJMXTest method setUp.
@Before
public void setUp() {
SpringBusFactory bf = new SpringBusFactory();
Bus bus = bf.createBus("/io/fabric8/cxf/endpoint/jaxrs/jmx-enable.xml");
BusFactory.setDefaultBus(bus);
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(BookStore.class, BookStoreSpring.class);
sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
sf.setResourceProvider(BookStoreSpring.class, new SingletonResourceProvider(new BookStoreSpring(), true));
sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
sf.setAddress("local://books");
sf.getFeatures().add(new ManagedApiFeature());
localServer = sf.create();
}
use of io.fabric8.annotations.Endpoint in project fabric8 by jboss-fuse.
the class DetectingGateway method route.
public void route(final SocketWrapper socket, ConnectionParameters params, final Buffer received) {
NetClient client = null;
if (params.protocolVirtualHost == null) {
params.protocolVirtualHost = defaultVirtualHost;
}
HashSet<String> schemes = new HashSet<String>(Arrays.asList(params.protocolSchemes));
if (params.protocolVirtualHost != null) {
List<ServiceDetails> services = serviceMap.getServices(params.protocolVirtualHost);
// Lets try again with the defaultVirtualHost
if (services.isEmpty() && !params.protocolVirtualHost.equals(defaultVirtualHost)) {
params.protocolVirtualHost = defaultVirtualHost;
services = serviceMap.getServices(params.protocolVirtualHost);
}
LOG.debug(String.format("%d services match the virtual host", services.size()));
if (!services.isEmpty()) {
ClientRequestFacade clientRequestFacade = clientRequestFacadeFactory.create(socket, params);
ServiceDetails serviceDetails = serviceLoadBalancer.choose(services, clientRequestFacade);
if (serviceDetails != null) {
List<String> urlStrings = serviceDetails.getServices();
LOG.debug("Selected service exposes the following URLS: {}", urlStrings);
for (String urlString : urlStrings) {
if (Strings.notEmpty(urlString)) {
// lets create a client for this request...
try {
URI uri = new URI(urlString);
// URL url = new URL(urlString);
String urlProtocol = uri.getScheme();
if (schemes.contains(urlProtocol)) {
if (!socket.remoteAddress().toString().equals(clientRequestFacade.getClientRequestKey())) {
LOG.info(String.format("Connecting client from '%s' (with key '%s') requesting virtual host '%s' to '%s:%d' using the %s protocol", socket.remoteAddress(), clientRequestFacade.getClientRequestKey(), params.protocolVirtualHost, uri.getHost(), uri.getPort(), params.protocol));
} else {
LOG.info(String.format("Connecting client from '%s' requesting virtual host '%s' to '%s:%d' using the %s protocol", socket.remoteAddress(), params.protocolVirtualHost, uri.getHost(), uri.getPort(), params.protocol));
}
client = createClient(params, socket, uri, received);
break;
}
} catch (URISyntaxException e) {
LOG.warn("Failed to parse URI: " + urlString + ". " + e, e);
}
}
}
}
}
}
if (client == null) {
// failed to route
handleConnectFailure(socket, String.format("No endpoint available for virtual host '%s' and protocol %s", params.protocolVirtualHost, params.protocol));
}
}
Aggregations