import spark.Request; import spark.Response; import spark.Route; import spark.Spark; public class HelloWorldSparkStyle { public static void main(String[] args){ Spark.get("/", new Route() { public Object handle(final Request request, final Response response){ return "Hello World from Spark"; } }); } }
final Route route = new Route(); route.setName(leg.getString("start_address") + " to " + leg.getString("end_address")); route.setCopyright(jsonRoute.getString("copyrights")); route.setLength(leg.getJSONObject("distance").getInt("value")); route.setWarning(jsonRoute.getJSONArray("warnings").getString(0)); route.addPoints(decodePolyLine(step.getJSONObject("polyline").getString("points"))); route.addSegment(segment.copy());
public RouteBuilder(Route instance,Boolean validationEnabled){ this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withSpec(instance.getSpec()); this.withStatus(instance.getStatus()); this.validationEnabled = validationEnabled; }
@Override public String getURL(Service service, String portName, String namespace, KubernetesClient client) { String serviceName = service.getMetadata().getName(); ServicePort port = URLFromServiceUtil.getServicePortByName(service, portName); if(port != null && port.getName() != null && isOpenShift(client)) { try { String serviceProtocol = port.getProtocol(); OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); Route route = openShiftClient.routes().inNamespace(namespace).withName(service.getMetadata().getName()).get(); if (route != null) { return (serviceProtocol + "://" + route.getSpec().getHost()).toLowerCase(); } } catch (KubernetesClientException e) { if(e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) { logger.warn("Could not lookup route:" + serviceName + " in namespace:"+ namespace +", due to: " + e.getMessage()); } } } return null; }
private void validateRoutesMatchServices(OpenShiftEnvironment env) throws ValidationException { Set<String> recipeServices = env.getServices() .values() .stream() .map(s -> s.getMetadata().getName()) .collect(Collectors.toSet()); for (Route route : env.getRoutes().values()) { if (route.getSpec() == null || route.getSpec().getTo() == null || !route.getSpec().getTo().getKind().equals(SERVICE_KIND)) { continue; } String serviceName = route.getSpec().getTo().getName(); if (!recipeServices.contains(serviceName)) { throw new ValidationException( String.format( "Route '%s' refers to Service '%s'. Routes must refer to Services included in recipe", route.getMetadata().getName(), serviceName)); } } } }
Route route = new Route(); Scanner scanner = new Scanner(System.in); route.setName(name); route.setStartLocation(startDest); route.setEndLocation(endDest); route.setStopList(new ArrayList<String>()); for(int i = 1; i<=numberOfStops; i++){ route.getStopList().add(scanner.next());
private Route createRouteForService(String routeDomainPostfix, String namespace, Service service) { Route route = null; String id = KubernetesHelper.getName(service); if (StringUtils.isNotBlank(id) && hasExactlyOneService(service, id)) { route = new Route(); ObjectMeta routeMeta = KubernetesHelper.getOrCreateMetadata(route); routeMeta.setName(id); routeMeta.setNamespace(namespace); RouteSpec routeSpec = new RouteSpec(); RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build(); //objectRef.setNamespace(namespace); routeSpec.setTo(objectRef); if (StringUtils.isNotBlank(routeDomainPostfix)) { routeSpec.setHost(prepareHostForRoute(routeDomainPostfix, id)); } else { routeSpec.setHost(""); } route.setSpec(routeSpec); String json; try { json = ResourceUtil.toJson(route); } catch (JsonProcessingException e) { json = e.getMessage() + ". object: " + route; } log.debug("Created route: " + json); } return route; }
Route route = new Route(); double distance = route.getDistance();
ArrayList<LatLng> allatlng = new ArrayList<LatLng>(); LatLng latlng = new LatLng(Double.parseDouble(strDestlat), Double.parseDouble(strDestlng)); allatlng.add(latlng); LatLng latlng1 = new LatLng(Double.parseDouble(strCurrentLat), Double.parseDouble(strCurrentLong)); allatlng.add(latlng1); Route route = new Route(); route.drawRoute(googleMap, Home.this, allatlng, true, Route.LANGUAGE_ENGLISH, true);
public OpenShiftServerResolver(List<Service> services, List<Route> routes) { super(services, Collections.emptyList()); this.routes = ArrayListMultimap.create(); for (Route route : routes) { String machineName = Annotations.newDeserializer(route.getMetadata().getAnnotations()).machineName(); this.routes.put(machineName, route); } }
public class Navigator { private GPS gps; private UserInterface ui; public Navigator(UserInterface ui, GPS gps) { this.ui = ui; this.gps = gps; } public void display() { String destination = ui.getDestEntry().getText(); Route theRoute = new Route(gps.getLocation(), destination); theRoute.calculateRoute(); MapView theMap = new MapView(); theMap.plot(theRoute); } } public class GPS { public String getLocation() { ... } }
/** * Checks if the Route already has an assigned address. * * @param namespace The namespace. * @param name The route name. */ public boolean isAddressReady(String namespace, String name) { Resource<Route, DoneableRoute> resourceOp = operation().inNamespace(namespace).withName(name); Route resource = resourceOp.get(); if (resource != null && resource.getStatus() != null && resource.getStatus().getIngress() != null && resource.getStatus().getIngress().size() > 0) { if (resource.getStatus().getIngress().get(0).getHost() != null) { return true; } } return false; } }
public RouteBuilder( RouteFluent<?> fluent , Route instance ){ this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withSpec(instance.getSpec()); fluent.withStatus(instance.getStatus()); } public RouteBuilder( Route instance ){
private void fillRouteServers(Route route, Map<String, ServerImpl> servers) { Annotations.newDeserializer(route.getMetadata().getAnnotations()) .servers() .forEach( (name, config) -> servers.put( name, newServer( config.getProtocol(), route.getSpec().getHost(), null, config.getPath(), config.getAttributes()))); } }
final Route route = new Route(); route.setName(leg.getString("start_address") + " to " + leg.getString("end_address")); route.setCopyright(jsonRoute.getString("copyrights")); route.setLength(leg.getJSONObject("distance").getInt("value")); route.setWarning(jsonRoute.getJSONArray("warnings").getString(0)); route.addPoints(decodePolyLine(step.getJSONObject("polyline").getString("points"))); route.addSegment(segment.copy());
public static Route createRouteForService(String routeDomainPostfix, String namespace, Service service, Logger log) { Route route = null; String id = KubernetesHelper.getName(service); if (Strings.isNotBlank(id) && shouldCreateRouteForService(log, service, id)) { route = new Route(); String routeId = id; KubernetesHelper.setName(route, namespace, routeId); RouteSpec routeSpec = new RouteSpec(); RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build(); //objectRef.setNamespace(namespace); routeSpec.setTo(objectRef); if (Strings.isNotBlank(routeDomainPostfix)) { // Let Openshift determine the route host when the domain is not set String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), "."); String namespaceSuffix = "-" + namespace; routeSpec.setHost(host + namespaceSuffix + "." + Strings.stripPrefix(routeDomainPostfix, ".")); } route.setSpec(routeSpec); String json = null; try { json = KubernetesHelper.toJson(route); } catch (JsonProcessingException e) { json = e.getMessage() + ". object: " + route; } } return route; }
void marshal() throws Exception { Route route = new Route(); route.setCna( "cnavalue" ); JAXBContext jc = JAXBContext.newInstance( Route.class ); Marshaller m = jc.createMarshaller(); m.setProperty( "jaxb.fragment", true ); StringWriter sw = new StringWriter(); m.marshal( route, sw ); System.out.println( sw.toString() ); }