use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class HttpGatewayHandler method handle.
@Override
public void handle(HttpServerRequest request) {
long callStart = System.nanoTime();
LOG.debug("Proxying request: {} {}", request.method(), request.uri());
// lets map the request URI to map to the service URI and then the renaming URI
// using mapping rules...
Map<String, MappedServices> mappingRules = httpGateway.getMappedServices();
try {
if (isMappingIndexRequest(request)) {
// lets return the JSON of all the results
doReturnIndex(request, mappingRules);
} else {
doRouteRequest(mappingRules, request);
}
CallDetailRecord cdr = new CallDetailRecord(System.nanoTime() - callStart, null);
httpGateway.addCallDetailRecord(cdr);
} catch (Throwable e) {
LOG.error("Caught: " + e, e);
CallDetailRecord cdr = new CallDetailRecord(System.nanoTime() - callStart, new Date() + ":" + e.getMessage());
httpGateway.addCallDetailRecord(cdr);
request.response().setStatusCode(404);
StringWriter buffer = new StringWriter();
e.printStackTrace(new PrintWriter(buffer));
request.response().setStatusMessage("Error: " + e + "\nStack Trace: " + buffer);
request.response().close();
}
}
use of io.fabric8.patch.Service in project ephemerals by LivePersonInc.
the class KubernetesDeploymentHandler method deploy.
@Override
public DeploymentEndpoints deploy(Deployment deployment) {
// Create service on KubernetesServiceBuilder cluster
Service service = kubernetesDeploymentStrategy.service(deployment);
kubernetesClient.services().inNamespace(kubernetesClient.getNamespace()).create(service);
// Create pods and replication controller
ReplicationController replicationController = kubernetesDeploymentStrategy.replicationController(deployment);
kubernetesClient.replicationControllers().inNamespace(kubernetesClient.getNamespace()).create(replicationController);
// Wait for deployment to finish by polling KubernetesServiceBuilder and waiting for 'FINISHED' status
KubernetesDeploymentStatusWaiter deploymentStatusWaiter = new KubernetesDeploymentStatusWaiter(kubernetesClient, deployment, DeploymentStatus.FINISHED);
try {
deploymentStatusWaiter.start();
} catch (TimeoutException e) {
throw new DeploymentException(e);
}
DeploymentEndpoints endpoints = new DeploymentEndpoints();
for (DeploymentPort deploymentPort : deployment.getDeploymentUnit().getPorts()) {
KubernetesDeploymentEndpointWaiter kubernetesDeploymentEndpointWaiter = new KubernetesDeploymentEndpointWaiter(kubernetesClient, deployment, deploymentPort);
try {
kubernetesDeploymentEndpointWaiter.start();
endpoints.add(kubernetesDeploymentEndpointWaiter.getEndpoint());
} catch (TimeoutException e) {
throw new DeploymentException(e);
}
}
return endpoints;
}
use of io.fabric8.patch.Service in project ephemerals by LivePersonInc.
the class KubernetesDeploymentHandler method destroy.
@Override
public void destroy(Deployment deployment) {
List<ReplicationController> apps = kubernetesClient.replicationControllers().withLabel(DEPLOYMENT_LABEL_KEY, deployment.getId()).list().getItems();
for (ReplicationController rc : apps) {
String deploymentId = rc.getMetadata().getName();
logger.info("Deleting service, replication controller and pods for deployment: {}", deploymentId);
Service svc = kubernetesClient.services().withName(deploymentId).get();
if (svc.getSpec().getType().equals(KubernetesServiceType.LOAD_BALANCER.getValue())) {
KubernetesLoadBalancerWaiter kubernetesLoadBalancerWaiter = new KubernetesLoadBalancerWaiter(kubernetesClient, deployment);
try {
kubernetesLoadBalancerWaiter.start();
} catch (TimeoutException e) {
throw new DeploymentException(e);
}
}
Boolean svcDeleted = kubernetesClient.services().withName(deploymentId).delete();
logger.info("Deleted service for deployment: {} {}", deploymentId, svcDeleted);
Boolean rcDeleted = kubernetesClient.replicationControllers().withName(deploymentId).delete();
logger.info("Deleted replication controller for deployment: {} {}", deploymentId, rcDeleted);
Map<String, String> selector = new HashMap<>();
selector.put(DEPLOYMENT_LABEL_KEY, deploymentId);
Boolean podDeleted = kubernetesClient.pods().withLabels(selector).delete();
logger.info("Deleted pods for deployment: {} {}", deploymentId, podDeleted);
}
}
use of io.fabric8.patch.Service in project halyard by spinnaker.
the class LocalDebianServiceProvider method getInstallCommand.
@Override
public String getInstallCommand(DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, Map<String, String> installCommands) {
Map<String, Object> bindings = new HashMap<>();
List<SpinnakerService.Type> serviceTypes = new ArrayList<>(installCommands.keySet()).stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
List<String> upstartNames = getLocalServices(serviceTypes).stream().filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()).map(i -> ((LocalDebianService) i).getUpstartServiceName()).filter(Objects::nonNull).collect(Collectors.toList());
List<String> systemdServiceConfigs = upstartNames.stream().map(n -> n + ".service").collect(Collectors.toList());
List<String> serviceInstalls = serviceTypes.stream().map(t -> installCommands.get(t.getCanonicalName())).collect(Collectors.toList());
TemplatedResource resource = new StringReplaceJarResource("/debian/init.sh");
bindings.put("services", Strings.join(upstartNames, " "));
bindings.put("systemd-service-configs", Strings.join(systemdServiceConfigs, " "));
String upstartInit = resource.setBindings(bindings).toString();
BillOfMaterials.ArtifactSources artifactSources = artifactService.getArtifactSources(deploymentDetails.getDeploymentName());
resource = new StringReplaceJarResource("/debian/install.sh");
bindings = new HashMap<>();
bindings.put("prepare-environment", "true");
bindings.put("install-redis", "true");
bindings.put("debian-repository", artifactSourcesConfig.mergeWithBomSources(artifactSources).getDebianRepository());
bindings.put("install-commands", String.join("\n", serviceInstalls));
bindings.put("service-action", "restart");
bindings.put("upstart-init", upstartInit);
return resource.setBindings(bindings).toString();
}
use of io.fabric8.patch.Service in project fabric8-maven-plugin by fabric8io.
the class PortForwardServiceTest method testSimpleScenario.
@Test
public void testSimpleScenario() throws Exception {
// Cannot test more complex scenarios due to errors in mockwebserver
OpenShiftMockServer mockServer = new OpenShiftMockServer(false);
Pod pod1 = new PodBuilder().withNewMetadata().withName("mypod").addToLabels("mykey", "myvalue").withResourceVersion("1").endMetadata().withNewStatus().withPhase("run").endStatus().build();
PodList pods1 = new PodListBuilder().withItems(pod1).withNewMetadata().withResourceVersion("1").endMetadata().build();
mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=mykey%3Dmyvalue").andReturn(200, pods1).always();
mockServer.expect().get().withPath("/api/v1/namespaces/test/pods").andReturn(200, pods1).always();
mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?labelSelector=mykey%3Dmyvalue&watch=true").andUpgradeToWebSocket().open().waitFor(1000).andEmit(new WatchEvent(pod1, "MODIFIED")).done().always();
mockServer.expect().get().withPath("/api/v1/namespaces/test/pods?resourceVersion=1&watch=true").andUpgradeToWebSocket().open().waitFor(1000).andEmit(new WatchEvent(pod1, "MODIFIED")).done().always();
OpenShiftClient client = mockServer.createOpenShiftClient();
PortForwardService service = new PortForwardService(clientToolsService, logger, client) {
@Override
public ProcessUtil.ProcessExecutionContext forwardPortAsync(Logger externalProcessLogger, String pod, int remotePort, int localPort) throws Fabric8ServiceException {
return new ProcessUtil.ProcessExecutionContext(process, Collections.<Thread>emptyList(), logger);
}
};
try (Closeable c = service.forwardPortAsync(logger, new LabelSelectorBuilder().withMatchLabels(Collections.singletonMap("mykey", "myvalue")).build(), 8080, 9000)) {
Thread.sleep(3000);
}
}
Aggregations