use of io.fabric8.annotations.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithBothNamespaceAndCriteria.
@Test(description = "Test .listServices(Namespace, Criteria) method")
public void testListServicesWithBothNamespaceAndCriteria() 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);
Map<String, String> oneLabel = createOneLabelHashMap();
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withLabels(oneLabel)).thenReturn(baseOperation);
Mockito.when(baseOperation.list()).thenReturn(createServiceListWithBothNamespaceAndCriteria());
List<Endpoint> endpoints = sdKubernetes.listServices("dev", oneLabel);
Assert.assertEquals(endpoints.size(), 2);
}
use of io.fabric8.annotations.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithoutCLusterIPAndExternalName.
@Test(description = "Test .listServices() method without ClusterIPs and ExternalNamesURLs")
public void testListServicesWithoutCLusterIPAndExternalName() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Not include ClusterIPs
sdKubernetes.setIncludeClusterIP(false);
// Not include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(false);
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(), 5);
Mockito.verify(openShiftClient, Mockito.times(2)).getMasterUrl();
}
use of io.fabric8.annotations.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithNamespace.
@Test(description = "Test .listServices(Namespace) method")
public void testListServicesWithNamespace() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Not include ClusterIPs
sdKubernetes.setIncludeClusterIP(false);
// Include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(true);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceListWithNamespace());
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices("dev");
Assert.assertEquals(endpoints.size(), 4);
}
use of io.fabric8.annotations.Endpoint in project fabric8 by jboss-fuse.
the class FabricCxfRegistrationHandler method registerApiEndpoint.
protected void registerApiEndpoint(Container container, ObjectName oName, String address, boolean started) {
String actualEndpointUrl = null;
try {
String url;
String id = container.getId();
if (isFullAddress(address)) {
url = toPublicAddress(id, address);
} else {
String cxfBus = getCxfServletPath(oName);
url = "${zk:" + id + "/http}" + cxfBus + address;
}
actualEndpointUrl = ZooKeeperUtils.getSubstitutedData(curator.get(), url);
// lets assume these locations are hard coded
// may be nice to discover from JMX one day
String apiDocPath = "/api-docs";
String wsdlPath = "?wsdl";
String wadlPath = "?_wadl";
Version version = container.getVersion();
String versionId = version != null ? version.getId() : null;
String json = "{\"id\":" + JsonHelper.jsonEncodeString(id) + ", \"container\":" + JsonHelper.jsonEncodeString(id) + ", \"version\":" + JsonHelper.jsonEncodeString(versionId) + ", \"services\":[" + JsonHelper.jsonEncodeString(url) + "]" + ", \"objectName\":" + JsonHelper.jsonEncodeString(oName.toString()) + "";
boolean rest = false;
if (booleanAttribute(oName, "isWADL")) {
rest = true;
json += ", \"wadl\":" + JsonHelper.jsonEncodeString(wadlPath);
}
if (booleanAttribute(oName, "isSwagger")) {
rest = true;
json += ", \"apidocs\":" + JsonHelper.jsonEncodeString(apiDocPath);
}
if (booleanAttribute(oName, "isWSDL")) {
json += ", \"wsdl\":" + JsonHelper.jsonEncodeString(wsdlPath);
}
json += "}";
String path = getPath(container, oName, address, rest);
LOGGER.info("Registered CXF API at " + path + " JSON: " + json);
if (!started && !rest) {
LOGGER.warn("Since the CXF service isn't started, this could really be a REST endpoint rather than WSDL at " + path);
}
registeredZkPaths.add(path);
registeredUrls.put(oName.toString(), address);
ZooKeeperUtils.setData(curator.get(), path, json, CreateMode.EPHEMERAL);
} catch (Exception e) {
LOGGER.error("Failed to register API endpoint for {}.", actualEndpointUrl, e);
}
}
use of io.fabric8.annotations.Endpoint in project fabric8 by jboss-fuse.
the class Manager method removed.
@SuppressWarnings("unchecked")
public void removed(final Collection listenerInfos) {
for (ListenerInfo listenerInfo : (Collection<ListenerInfo>) listenerInfos) {
// Ignore our own listeners or those that don't have any filter
if (listenerInfo.getBundleContext() == bundleContext || listenerInfo.getFilter() == null) {
continue;
}
SimpleFilter exFilter = listeners.remove(listenerInfo);
// Iterate through known services and dereference them if needed
Set<EndpointDescription> matches = remoteEndpoints.match(exFilter);
for (EndpointDescription endpoint : matches) {
Map<Long, ImportRegistration> registrations = importedServices.get(endpoint);
if (registrations != null) {
ImportRegistration registration = registrations.get(listenerInfo.getBundleContext().getBundle().getBundleId());
if (registration != null) {
registration.removeReference(listenerInfo);
if (!registration.hasReferences()) {
registration.getImportedService().unregister();
registrations.remove(listenerInfo.getBundleContext().getBundle().getBundleId());
}
}
}
}
}
}
Aggregations