Search in sources :

Example 1 with ServiceDiscoveryException

use of org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method listServices.

/**
 * {@inheritDoc}
 */
@Override
public List<Endpoint> listServices(String namespace, Map<String, String> criteria) throws ServiceDiscoveryException {
    List<Endpoint> endpointList = new ArrayList<>();
    if (client != null) {
        log.debug("Looking for services, with the specified labels, in namespace {}", namespace);
        try {
            List<Service> serviceList = client.services().inNamespace(namespace).withLabels(criteria).list().getItems();
            addServicesToEndpointList(serviceList, endpointList);
        } catch (KubernetesClientException | MalformedURLException e) {
            String msg = "Error occurred while trying to list services using Kubernetes client";
            throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
        } catch (NoSuchMethodError e) {
            String msg = "Filtering criteria in the deployment yaml includes unwanted characters";
            throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
        }
    }
    return endpointList;
}
Also used : MalformedURLException(java.net.MalformedURLException) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 2 with ServiceDiscoveryException

use of org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method listServices.

/**
 * {@inheritDoc}
 */
@Override
public List<Endpoint> listServices() throws ServiceDiscoveryException {
    List<Endpoint> endpointList = new ArrayList<>();
    if (client != null) {
        log.debug("Looking for services in all namespaces");
        try {
            List<Service> serviceList = client.services().inNamespace(null).list().getItems();
            addServicesToEndpointList(serviceList, endpointList);
        } catch (KubernetesClientException | MalformedURLException e) {
            String msg = "Error occurred while trying to list services using Kubernetes client";
            throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
        }
    }
    return endpointList;
}
Also used : MalformedURLException(java.net.MalformedURLException) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 3 with ServiceDiscoveryException

use of org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method listServices.

/**
 * {@inheritDoc}
 */
@Override
public List<Endpoint> listServices(String namespace) throws ServiceDiscoveryException {
    List<Endpoint> endpointList = new ArrayList<>();
    if (client != null) {
        log.debug("Looking for services in namespace {}", namespace);
        try {
            List<Service> serviceList = client.services().inNamespace(namespace).list().getItems();
            addServicesToEndpointList(serviceList, endpointList);
        } catch (KubernetesClientException | MalformedURLException e) {
            String msg = "Error occurred while trying to list services using Kubernetes client";
            throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
        }
    }
    return endpointList;
}
Also used : MalformedURLException(java.net.MalformedURLException) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 4 with ServiceDiscoveryException

use of org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method resolveToken.

/**
 * Get the token after decrypting using {@link FileEncryptionUtility#readFromEncryptedFile(java.lang.String)}
 *
 * @return service account token
 * @throws ServiceDiscoveryException if an error occurs while resolving the token
 */
private String resolveToken(String encryptedTokenFileName) throws ServiceDiscoveryException {
    String token;
    try {
        String externalSATokenFilePath = System.getProperty(FileEncryptionUtility.CARBON_HOME) + FileEncryptionUtility.SECURITY_DIR + File.separator + encryptedTokenFileName;
        token = FileEncryptionUtility.getInstance().readFromEncryptedFile(externalSATokenFilePath);
    } catch (APIManagementException e) {
        String msg = "Error occurred while resolving externally stored token";
        throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
    }
    return StringUtils.replace(token, "\n", "");
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException)

Example 5 with ServiceDiscoveryException

use of org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetes method listServices.

/**
 * {@inheritDoc}
 */
@Override
public List<Endpoint> listServices(Map<String, String> criteria) throws ServiceDiscoveryException {
    List<Endpoint> endpointList = new ArrayList<>();
    if (client != null) {
        log.debug("Looking for services, with the specified labels, in all namespaces");
        try {
            // namespace has to be set to null to check all allowed namespaces
            List<Service> serviceList = client.services().inNamespace(null).withLabels(criteria).list().getItems();
            addServicesToEndpointList(serviceList, endpointList);
        } catch (KubernetesClientException | MalformedURLException e) {
            String msg = "Error occurred while trying to list services using Kubernetes client";
            throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
        } catch (NoSuchMethodError e) {
            String msg = "Filtering criteria in the deployment yaml includes unwanted characters";
            throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
        }
    }
    return endpointList;
}
Also used : MalformedURLException(java.net.MalformedURLException) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) Service(io.fabric8.kubernetes.api.model.Service) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

ServiceDiscoveryException (org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException)9 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 ArrayList (java.util.ArrayList)5 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)5 Service (io.fabric8.kubernetes.api.model.Service)4 MalformedURLException (java.net.MalformedURLException)4 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 DefaultOpenShiftClient (io.fabric8.openshift.client.DefaultOpenShiftClient)1 ServiceDiscoveryConfigurations (org.wso2.carbon.apimgt.core.configuration.models.ServiceDiscoveryConfigurations)1 ServiceDiscoveryImplConfig (org.wso2.carbon.apimgt.core.configuration.models.ServiceDiscoveryImplConfig)1 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)1