use of io.fabric8.kubernetes.client.KubernetesClientException 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;
}
use of io.fabric8.kubernetes.client.KubernetesClientException in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method initImpl.
/**
* Initializes OpenShiftClient (extended KubernetesClient) and sets the necessary parameters
*
* @param implParameters implementation parameters added by the super class #initImpl(java.util.Map) method
* @throws ServiceDiscoveryException if an error occurs while initializing the client
*/
@Override
public void initImpl(Map<String, String> implParameters) throws ServiceDiscoveryException {
try {
setClient(new DefaultOpenShiftClient(buildConfig(implParameters)));
} catch (KubernetesClientException | APIMgtDAOException e) {
String msg = "Error occurred while creating Kubernetes client";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
} catch (ArrayIndexOutOfBoundsException e) {
String msg = "Error occurred while reading filtering criteria from the configuration";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_INITIALIZING_SERVICE_DISCOVERY);
}
includeClusterIP = Boolean.parseBoolean(implParameters.get(INCLUDE_CLUSTER_IPS));
includeExternalNameTypeServices = Boolean.parseBoolean(implParameters.get(INCLUDE_EXTERNAL_NAME_SERVICES));
}
use of io.fabric8.kubernetes.client.KubernetesClientException in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method createServiceResource.
/**
* Create a service in cms
*
* @param serviceTemplate Service template as a String
* @param serviceName Name of the service
* @throws ContainerBasedGatewayException if failed to create a service
*/
private void createServiceResource(String serviceTemplate, String serviceName) throws ContainerBasedGatewayException {
HasMetadata resource = getResourcesFromTemplate(serviceTemplate);
try {
if (resource instanceof Service) {
// check whether there are existing service already
if (client.services().inNamespace(namespace).withName(serviceName).get() == null) {
log.debug("Deploying in CMS type: {} and the Service resource definition: {} ", cmsType, serviceTemplate);
Service service = (Service) resource;
Service result = client.services().inNamespace(namespace).create(service);
log.info("Created Service : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
} else {
log.info("There exist a service with the same name in " + cmsType + ". Service name : " + serviceName);
}
} else {
throw new ContainerBasedGatewayException("Loaded Resource is not a Service in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
}
} catch (KubernetesClientException e) {
throw new ContainerBasedGatewayException("Error while creating container based gateway service in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
}
}
use of io.fabric8.kubernetes.client.KubernetesClientException in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method removeContainerBasedGateway.
/**
* @see ContainerBasedGatewayGenerator#removeContainerBasedGateway(String, API) (String)
*/
@Override
public void removeContainerBasedGateway(String label, API api) throws ContainerBasedGatewayException {
try {
client.services().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete();
client.extensions().deployments().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete();
client.extensions().ingresses().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete();
log.info(String.format("Completed deleting the container gateway related %s deployment, service and " + "ingress resources.", cmsType));
} catch (KubernetesClientException e) {
throw new ContainerBasedGatewayException("Error while removing container based gateway", e, ExceptionCodes.CONTAINER_GATEWAY_REMOVAL_FAILED);
}
}
use of io.fabric8.kubernetes.client.KubernetesClientException in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method initImpl.
/**
* @see ContainerBasedGatewayGenerator#initImpl(Map)
*/
@Override
void initImpl(Map<String, String> implParameters) throws ContainerBasedGatewayException {
try {
setValues(implParameters);
setClient(new DefaultOpenShiftClient(buildConfig()));
} catch (KubernetesClientException e) {
String msg = "Error occurred while creating Default Openshift Client";
throw new ContainerBasedGatewayException(msg, e, ExceptionCodes.ERROR_INITIALIZING_DEDICATED_CONTAINER_BASED_GATEWAY);
}
}
Aggregations