Search in sources :

Example 6 with Endpoint

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);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with Endpoint

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();
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with Endpoint

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);
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with Endpoint

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);
    }
}
Also used : Version(io.fabric8.api.Version) URISyntaxException(java.net.URISyntaxException) BadBinaryOpValueExpException(javax.management.BadBinaryOpValueExpException) BadStringOperationException(javax.management.BadStringOperationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MalformedURLException(java.net.MalformedURLException) BadAttributeValueExpException(javax.management.BadAttributeValueExpException) IOException(java.io.IOException) InvalidApplicationException(javax.management.InvalidApplicationException)

Example 10 with Endpoint

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());
                    }
                }
            }
        }
    }
}
Also used : SimpleFilter(io.fabric8.dosgi.capset.SimpleFilter) Collection(java.util.Collection)

Aggregations

Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)12 Service (io.fabric8.kubernetes.api.model.Service)9 ArrayList (java.util.ArrayList)9 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)7 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)7 URL (java.net.URL)7 BeforeTest (org.testng.annotations.BeforeTest)7 Test (org.testng.annotations.Test)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 Endpoints (io.fabric8.kubernetes.api.model.Endpoints)4 ServiceDiscoveryException (org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 EndpointsList (io.fabric8.kubernetes.api.model.EndpointsList)3 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)3 File (java.io.File)3 Collection (java.util.Collection)3 Configuration (io.fabric8.annotations.Configuration)2 Endpoint (io.fabric8.annotations.Endpoint)2