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"; } }); } }
private void enrichSubjectsNamespace(OpenshiftRoleBindingBuilder builder) { builder.accept(new TypedVisitor<ObjectReferenceBuilder>() { @Override public void visit(ObjectReferenceBuilder o) { if (o.getKind() != null && o.getKind().equals("ServiceAccount") && (o.getNamespace() == null || o.getNamespace().isEmpty())) { o.withNamespace(getNamespace()); } } }); }
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 boolean isDeploymentConfigReady(DeploymentConfig d) { Utils.checkNotNull(d, "Deployment can't be null."); DeploymentConfigSpec spec = d.getSpec(); DeploymentConfigStatus status = d.getStatus(); if (status == null || status.getReplicas() == null || status.getAvailableReplicas() == null) { return false; } //Can be true in testing, so handle it to make test writing easier. if (spec == null || spec.getReplicas() == null) { return false; } return spec.getReplicas().intValue() == status.getReplicas() && spec.getReplicas().intValue() <= status.getAvailableReplicas(); }
@Override public DeploymentConfig deployLatest(boolean wait) { Long currentVersion = getMandatory().getStatus().getLatestVersion(); if(currentVersion == null){ currentVersion = 1L; } DeploymentConfig deployment = cascading(false).edit().editStatus().withLatestVersion(++currentVersion).endStatus().done(); if (wait) { waitUntilDeploymentConfigIsScaled(deployment.getSpec().getReplicas()); deployment = getMandatory(); } return deployment; }
public static void main(String[] args) throws InterruptedException { try (OpenShiftClient client = new DefaultOpenShiftClient()) { SecurityContextConstraints scc = new SecurityContextConstraintsBuilder() .withNewMetadata().withName("scc").endMetadata() .withAllowPrivilegedContainer(true) .withNewRunAsUser() .withType("RunAsAny") .endRunAsUser() .withNewSeLinuxContext() .withType("RunAsAny") .endSeLinuxContext() .withNewFsGroup() .withType("RunAsAny") .endFsGroup() .withNewSupplementalGroups() .withType("RunAsAny") .endSupplementalGroups() .addToUsers("admin") .addToGroups("admin-group") .build(); log("Created SecurityContextConstraints", client.securityContextConstraints().create(scc)); client.close(); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } }
@Override public DeploymentConfig scale(int count, boolean wait) { DeploymentConfig deployment = cascading(false).edit().editSpec().withReplicas(count).endSpec().done(); if (wait) { waitUntilDeploymentConfigIsScaled(count); deployment = getMandatory(); } return deployment; }
public static void main(String[] args) throws InterruptedException { String namespace = "myproject"; String master = "CLUSTER_URL"; Config config = new ConfigBuilder().withMasterUrl(master).build(); OpenShiftClient client = new DefaultOpenShiftClient(config); try { ImageStreamTag istag = new ImageStreamTagBuilder().withNewMetadata().withName("bar1:1.0.12").endMetadata() .withNewTag().withNewFrom().withKind("DockerImage").withName("openshift/wildfly-81-centos7:latest").endFrom().endTag() .build(); log("Created istag", client.imageStreamTags().inNamespace(namespace).create(istag)); Thread.sleep(30000); }finally { log("ImageStreamTags are :"); log(client.imageStreamTags().inNamespace(namespace).withName("bar1:1.0.12").get().toString()); log("ImageStreamTags using list are :"); log(client.imageStreamTags().list().getItems().get(0).toString()); log("Deleted istag",client.imageStreamTags().withName("bar1:1.0.12").delete()); client.close(); } }
public static void main(String[] args) throws InterruptedException { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try (OpenShiftClient client = new DefaultOpenShiftClient(config)) { ProjectRequest request = null; try { request = client.projectrequests().createNew().withNewMetadata().withName("thisisatest").endMetadata().withDescription("Jimmi").withDisplayName("Jimmi").done(); } finally { if (request != null) { client.projects().withName(request.getMetadata().getName()).delete(); } } } }
public void run() { DeploymentConfig deployment = operation.getMandatory(); if (observedGeneration <= deployment.getStatus().getObservedGeneration()) { countDownLatch.countDown(); } } };
@Override public void eventReceived(Action action, BuildConfig resource) { System.out.println(">> Action: " + action + " on BuildConfig " + resource.getMetadata().getName() + " with version: " + resource.getApiVersion()); }
private void enrichFromUsersAndGroups(OpenshiftRoleBindingBuilder builder, List<String> userNames, List<String> groupNames) { builder.withSubjects(); if (userNames != null) { for (String userName : userNames) { if (userName.startsWith("system:serviceaccount:")) { String[] splitUserName = userName.split(":"); if (splitUserName.length == 4) { builder.addNewSubject().withKind("ServiceAccount").withNamespace(splitUserName[2]).withName(splitUserName[3]).endSubject(); continue; } } builder.addNewSubject().withKind("User").withName(userName).endSubject(); } } if (groupNames != null) { for (String groupName : groupNames) { builder.addNewSubject().withKind("Group").withName(groupName).endSubject(); } } }
private OpenshiftRoleBinding enrichRoleBinding(OpenshiftRoleBinding binding) { OpenshiftRoleBindingBuilder builder = new OpenshiftRoleBindingBuilder(binding); if ((binding.getUserNames() != null && !binding.getUserNames().isEmpty()) || (binding.getGroupNames() != null && !binding.getGroupNames().isEmpty())) { enrichFromUsersAndGroups(builder, binding.getUserNames(), binding.getGroupNames()); } else { enrichFromSubjects(builder, binding.getSubjects()); enrichSubjectsNamespace(builder); } return builder.build(); }
private CreateableLocalSubjectAccessReviewImpl(OkHttpClient client) { this.client = client; this.builder = new LocalSubjectAccessReviewBuilder(CreateableLocalSubjectAccessReviewImpl.this); }
private CreateableSubjectAccessReviewImpl(OkHttpClient client) { this.client = client; this.builder = new SubjectAccessReviewBuilder(CreateableSubjectAccessReviewImpl.this); }
@Override public SubjectAccessReviewResponse done() { return create(builder.build()); } }
@Override public SubjectAccessReviewResponse done() { return create(builder.build()); } }
@Override public DoneableProjectRequest createNew() { return new DoneableProjectRequest(new Function<ProjectRequest, ProjectRequest>() { @Override public ProjectRequest apply(ProjectRequest item) { try { return create(item); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } } }); }
private ProjectRequest updateApiVersion(ProjectRequest p) { p.setApiVersion(this.apiGroupVersion); return p; }
@Override public void init() { get(new Route("/test") { @Override public Object handle(Request request, Response response) { return "response goes here; } });