use of io.fabric8.gateway.loadbalancer.LoadBalancer in project curiostack by curioswitch.
the class DeployDevDbPodTask method exec.
@TaskAction
public void exec() {
ImmutableDatabaseExtension config = getProject().getExtensions().getByType(DatabaseExtension.class);
PersistentVolumeClaim volumeClaim = new PersistentVolumeClaimBuilder().withMetadata(new ObjectMetaBuilder().withName(config.devDbPodName() + "-pvc").withNamespace(config.devDbPodNamespace()).build()).withSpec(new PersistentVolumeClaimSpecBuilder().withAccessModes("ReadWriteOnce").withResources(new ResourceRequirementsBuilder().withRequests(ImmutableMap.of("storage", new Quantity("5Gi"))).build()).build()).build();
Pod pod = new PodBuilder().withMetadata(new ObjectMetaBuilder().withName(config.devDbPodName()).withLabels(ImmutableMap.of("name", config.devDbPodName())).withNamespace(config.devDbPodNamespace()).build()).withSpec(new PodSpecBuilder().withContainers(new ContainerBuilder().withResources(new ResourceRequirementsBuilder().withLimits(ImmutableMap.of("cpu", new Quantity("0.1"), "memory", new Quantity("512Mi"))).build()).withImage(config.devDockerImageTag()).withName(config.devDbPodName()).withImagePullPolicy("Always").withPorts(new ContainerPortBuilder().withContainerPort(3306).withName("mysql").build()).withVolumeMounts(new VolumeMountBuilder().withName(config.devDbPodName() + "-data").withMountPath("/var/lib/mysql").build()).withArgs("--ignore-db-dir=lost+found").build()).withVolumes(new VolumeBuilder().withName(config.devDbPodName() + "-data").withPersistentVolumeClaim(new PersistentVolumeClaimVolumeSourceBuilder().withClaimName(volumeClaim.getMetadata().getName()).build()).build()).build()).build();
Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withName(config.devDbPodName()).withNamespace(config.devDbPodNamespace()).build()).withSpec(new ServiceSpecBuilder().withPorts(new ServicePortBuilder().withPort(3306).withTargetPort(new IntOrString(3306)).build()).withSelector(ImmutableMap.of("name", config.devDbPodName())).withType("LoadBalancer").withLoadBalancerSourceRanges(config.devDbIpRestrictions()).build()).build();
KubernetesClient client = new DefaultKubernetesClient();
try {
client.resource(volumeClaim).createOrReplace();
} catch (Exception e) {
// TODO(choko): Find a better way to idempotently setup.
// Ignore
}
try {
client.resourceList(pod).createOrReplace();
} catch (Exception e) {
// TODO(choko): Find a better way to idempotently setup.
// Ignore
}
client.resource(service).createOrReplace();
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method addServicesToEndpointList.
/**
* For each service in {@code serviceList} list, methods are called to add endpoints of different types,
* for each of service's ports
*
* @param serviceList filtered list of services
*/
private void addServicesToEndpointList(List<Service> serviceList, List<Endpoint> endpointList) throws MalformedURLException {
for (Service service : serviceList) {
// Set the parameters that does not change with the service port
String serviceName = service.getMetadata().getName();
String namespace = service.getMetadata().getNamespace();
Map<String, String> labelsMap = service.getMetadata().getLabels();
String labels = (labelsMap != null) ? labelsMap.toString() : "";
ServiceSpec serviceSpec = service.getSpec();
String serviceType = serviceSpec.getType();
if (includeExternalNameTypeServices && EXTERNAL_NAME.equals(serviceType)) {
// Since only a "ExternalName" type service can have an "externalName" (the alias in kube-dns)
addExternalNameEndpoint(serviceName, serviceSpec.getExternalName(), namespace, labels, endpointList);
}
for (ServicePort servicePort : serviceSpec.getPorts()) {
String protocol = servicePort.getName();
if (APIMgtConstants.HTTP.equals(protocol) || APIMgtConstants.HTTPS.equals(protocol)) {
int port = servicePort.getPort();
if (includeClusterIP && !EXTERNAL_NAME.equals(serviceType)) {
// Since almost every service has a cluster IP, except for ExternalName type
addClusterIPEndpoint(serviceName, serviceSpec.getClusterIP(), port, protocol, namespace, labels, endpointList);
}
if (NODE_PORT.equals(serviceType) || LOAD_BALANCER.equals(serviceType)) {
// Because both "NodePort" and "LoadBalancer" types of services have "NodePort" type URLs
addNodePortEndpoint(serviceName, servicePort.getNodePort(), protocol, namespace, labels, endpointList);
}
if (LOAD_BALANCER.equals(serviceType)) {
// Since only "LoadBalancer" type services have "LoadBalancer" type URLs
addLoadBalancerEndpoint(serviceName, service, port, protocol, namespace, labels, endpointList);
}
// A Special case (can be any of the service types above)
addExternalIPEndpoint(serviceName, serviceSpec.getExternalIPs(), port, protocol, namespace, labels, endpointList);
} else if (log.isDebugEnabled()) {
log.debug("Service:{} Namespace:{} Port:{}/{} Application level protocol not defined.", serviceName, namespace, servicePort.getPort(), protocol);
}
}
}
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method createMalformedServiceList.
/**
* Create ServiceList with the given port type, but without a loadBalancer ingress
*
* @param portType http or https or a wrong port to check behavior
* @return ServiceList containing one service of LoadBalancer type
*/
private ServiceList createMalformedServiceList(String portType) {
ServicePort port = new ServicePortBuilder().withName(portType).withPort(80).withNodePort(30005).build();
Service malformedService5 = new ServiceBuilder().withNewMetadata().withName("service5").withNamespace("prod").and().withNewSpec().withType("LoadBalancer").withClusterIP("1.1.1.5").withPorts(port).and().withNewStatus().withNewLoadBalancer().endLoadBalancer().and().build();
List<Service> servicesList = new ArrayList<>();
servicesList.add(malformedService5);
return new ServiceListBuilder().withItems(servicesList).build();
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class ExtendedBurnIn method startHttpGateway.
public HttpGatewayServer startHttpGateway() {
if (restEndpointServer != null) {
LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
ServiceDTO serviceDetails = new ServiceDTO();
serviceDetails.setContainer("local");
serviceDetails.setVersion("1");
mappedServices.put("/hello/world", new MappedServices("http://localhost:8181", serviceDetails, loadBalancer, false));
}
DetectingGatewayWebSocketHandler websocketHandler = new DetectingGatewayWebSocketHandler();
HttpGatewayHandler handler = new HttpGatewayHandler(vertx, new HttpGateway() {
@Override
public void addMappingRuleConfiguration(HttpMappingRule mappingRule) {
}
@Override
public void removeMappingRuleConfiguration(HttpMappingRule mappingRule) {
}
@Override
public Map<String, MappedServices> getMappedServices() {
return mappedServices;
}
@Override
public boolean isEnableIndex() {
return true;
}
@Override
public InetSocketAddress getLocalAddress() {
return new InetSocketAddress("0.0.0.0", 8080);
}
@Override
public void addCallDetailRecord(CallDetailRecord cdr) {
}
});
websocketHandler.setPathPrefix("");
httpGatewayServer = new HttpGatewayServer(vertx, handler, websocketHandler, 8080);
httpGatewayServer.setHost("localhost");
httpGatewayServer.init();
return httpGatewayServer;
}
use of io.fabric8.gateway.loadbalancer.LoadBalancer in project fabric8 by jboss-fuse.
the class HttpMappingRuleConfiguration method updateConfiguration.
private void updateConfiguration(Map<String, ?> configuration) throws Exception {
LOG.info("activating http mapping rule " + configuration);
configurer.configure(configuration, this);
LOG.info("activating http mapping rule " + zooKeeperPath + " on " + gateway.get().getPort());
String zkPath = getZooKeeperPath();
Objects.notNull(zkPath, "zooKeeperPath");
Objects.notNull(getUriTemplate(), "uriTemplate");
LoadBalancer loadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
LOG.info("activating http mapping ZooKeeper path: " + zkPath + " with URI template: " + uriTemplate + " enabledVersion: " + enabledVersion + " with load balancer: " + loadBalancer);
if (httpMappingRuleBase != null) {
gateway.get().removeMappingRuleConfiguration(httpMappingRuleBase);
}
httpMappingRuleBase = new HttpMappingRuleBase(new SimplePathTemplate(uriTemplate), gateway.get().getGatewayVersion(), enabledVersion, loadBalancer, reverseHeaders);
mappingTree = new HttpMappingZooKeeperTreeCache(curator.get(), httpMappingRuleBase, zooKeeperPath);
mappingTree.init();
gateway.get().addMappingRuleConfiguration(httpMappingRuleBase);
}
Aggregations