Java源码示例:io.fabric8.openshift.api.model.ProjectRequest

示例1
@Test
public void should_be_able_to_create_a_project_impersonating_service_account() {
  RequestConfig requestConfig = new RequestConfigBuilder()
  .withImpersonateUsername(SERVICE_ACCOUNT)
  .withImpersonateGroups("system:authenticated", "system:authenticated:oauth")
  .withImpersonateExtras(Collections.singletonMap("scopes", Collections.singletonList("development")))
  .build();

  // Create a project
  ProjectRequest projectRequest = client.withRequestConfig(requestConfig).call(c -> c.projectrequests().createNew()
    .withNewMetadata()
    .withName(NEW_PROJECT)
    .endMetadata()
    .done());

  // Grab the requester annotation
  String requester = projectRequest.getMetadata().getAnnotations().get("openshift.io/requester");
  assertThat(requester).isEqualTo(SERVICE_ACCOUNT);
}
 
示例2
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();
      }
    }
  }
}
 
示例3
@Override
public ProjectRequest create(ProjectRequest... resources) {
  try {
    if (resources.length > 1) {
      throw new IllegalArgumentException("Too many items to create.");
    } else if (resources.length == 1) {
      return handleCreate(updateApiVersion(resources[0]), ProjectRequest.class);
    } else if (getItem() == null) {
      throw new IllegalArgumentException("Nothing to create.");
    } else {
      return handleCreate(updateApiVersion(getItem()), ProjectRequest.class);
    }
  } catch (InterruptedException | ExecutionException | IOException e) {
    throw KubernetesClientException.launderThrowable(e);
  }
}
 
示例4
/**
 * Returns true if the ProjectRequest is created
 */
public boolean applyProjectRequest(ProjectRequest entity) {
    // Check whether project creation attempted before
    if (projectsCreated.contains(getName(entity))) {
        return false;
    }
    String namespace = getOrCreateMetadata(entity).getName();
    log.info("Using project: " + namespace);
    String name = getName(entity);
    Objects.requireNonNull(name, "No name for " + entity);
    OpenShiftClient openshiftClient = getOpenShiftClient();
    if (openshiftClient == null) {
        log.warn("Cannot check for Project " + namespace + " as not running against OpenShift!");
        return false;
    }
    boolean exists = checkNamespace(name);
    // We may want to be more fine-grained on the phase of the project
    if (!exists) {
        try {
            Object answer = openshiftClient.projectrequests().create(entity);
            // Add project to created projects
            projectsCreated.add(name);
            logGeneratedEntity("Created ProjectRequest: ", namespace, entity, answer);
            return true;
        } catch (Exception e) {
            onApplyError("Failed to create ProjectRequest: " + name + " due " + e.getMessage(), e);
        }
    }
    return false;
}
 
示例5
@Test
public void testCreate() {
  ProjectRequest req1 = new ProjectRequestBuilder().withApiVersion("v1").withNewMetadata().withName("req1").and().build();

 server.expect().withPath("/apis/project.openshift.io/v1/projectrequests").andReturn(201, req1).once();

  OpenShiftClient client = server.getOpenshiftClient();

  ProjectRequest result = client.projectrequests().create(req1);
  assertNotNull(result);
  assertEquals(req1, result);
}
 
示例6
/**
 * {@inheritDoc}
 */
@Override
public OpenShiftProject createProject(final String name) throws
        DuplicateProjectException,
        IllegalArgumentException {

    // Create
    final ProjectRequest projectRequest;
    try {
        projectRequest = client.projectrequests().createNew().
                withNewMetadata().
                withName(name).
                endMetadata().
                done();
    } catch (final KubernetesClientException kce) {
        // Detect if duplicate project
        if (kce.getCode() == CODE_DUPLICATE_PROJECT &&
                STATUS_REASON_DUPLICATE_PROJECT.equals(kce.getStatus().getReason())) {
            throw new DuplicateProjectException(name);
        }

        // Some other error, rethrow it
        throw kce;
    }

    // Block until exists
    int counter = 0;
    while (true) {
        counter++;
        if (projectExists(name)) {
            // We good
            break;
        }
        if (counter == 20) {
            throw new IllegalStateException("Newly-created project "
                                                    + name + " could not be found ");
        }
        log.finest("Couldn't find project " + name +
                           " after creating; waiting and trying again...");
        try {
            Thread.sleep(3000);
        } catch (final InterruptedException ie) {
            Thread.interrupted();
            throw new RuntimeException("Someone interrupted thread while finding newly-created project", ie);
        }
    }
    // Populate value object and return it
    final String roundtripDisplayName = projectRequest.getMetadata().getName();
    final OpenShiftProject project = new OpenShiftProjectImpl(roundtripDisplayName, consoleUrl.toString());

    return project;
}
 
示例7
public static void main(String[] args) throws InterruptedException {
  Config config = new ConfigBuilder().build();
  KubernetesClient kubernetesClient = new DefaultKubernetesClient(config);
  OpenShiftClient client = kubernetesClient.adapt(OpenShiftClient.class);

  try {
    ProjectRequest  projectRequest = new ProjectRequestBuilder()
        .withNewMetadata()
          .withName("thisisatest")
          .addToLabels("project", "thisisatest")
        .endMetadata()
        .build();


    log("Created project", client.projectrequests().create(projectRequest));

    ServiceAccount fabric8 = new ServiceAccountBuilder().withNewMetadata().withName("fabric8").endMetadata().build();

    client.serviceAccounts().inNamespace("thisisatest").createOrReplace(fabric8);

    log("Created deployment", client.deploymentConfigs().inNamespace("thisisatest").createOrReplaceWithNew()
      .withNewMetadata()
        .withName("nginx")
      .endMetadata()
      .withNewSpec()
        .withReplicas(1)
        .addNewTrigger()
          .withType("ConfigChange")
        .endTrigger()
        .addToSelector("app", "nginx")
        .withNewTemplate()
          .withNewMetadata()
            .addToLabels("app", "nginx")
          .endMetadata()
          .withNewSpec()
            .addNewContainer()
              .withName("nginx")
              .withImage("nginx")
              .addNewPort()
                .withContainerPort(80)
              .endPort()
            .endContainer()
          .endSpec()
        .endTemplate()
      .endSpec()
      .done());


    client.deploymentConfigs().inNamespace("thisisatest").withName("nginx").scale(2, true);
    log("Created pods:", client.pods().inNamespace("thisisatest").list().getItems());
    client.deploymentConfigs().inNamespace("thisisatest").withName("nginx").delete();
    log("Pods:", client.pods().inNamespace("thisisatest").list().getItems());
    log("Replication Controllers:", client.replicationControllers().inNamespace("thisisatest").list().getItems());

    log("Done.");
  }finally {
   // client.projects().withName("thisisatest").delete();
    client.close();
  }
}
 
示例8
private ProjectRequest updateApiVersion(ProjectRequest p) {
  if (p.getApiVersion() == null) {
    p.setApiVersion(this.apiGroupVersion);
  }
  return p;
}
 
示例9
@Override
public ProjectRequest create(ProjectRequest resource) {
  return create(new ProjectRequest[]{resource});
}
 
示例10
public ProjectRequest getItem() {
  return (ProjectRequest) context.getItem();
}
 
示例11
@Override
public ProjectRequest create(OkHttpClient client, Config config, String namespace, ProjectRequest item) {
    return new ProjectRequestsOperationImpl(client, OpenShiftConfig.wrap(config)).create(item);
}
 
示例12
@Override
public ProjectRequest replace(OkHttpClient client, Config config, String namespace, ProjectRequest item) {
  throw new UnsupportedOperationException();
}
 
示例13
@Override
public ProjectRequest reload(OkHttpClient client, Config config, String namespace, ProjectRequest item) {
  throw new UnsupportedOperationException();
}
 
示例14
@Override
public ProjectRequestBuilder edit(ProjectRequest item) {
  return new ProjectRequestBuilder(item);
}
 
示例15
@Override
public Boolean delete(OkHttpClient client, Config config, String namespace, DeletionPropagation propagationPolicy, ProjectRequest item) {
  throw new UnsupportedOperationException();
}
 
示例16
@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ProjectRequest item, Watcher<ProjectRequest> watcher) {
  throw new UnsupportedOperationException();
}
 
示例17
@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ProjectRequest item, String resourceVersion, Watcher<ProjectRequest> watcher) {
  throw new UnsupportedOperationException();
}
 
示例18
@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ProjectRequest item, ListOptions listOptions, Watcher<ProjectRequest> watcher) {
  throw new UnsupportedOperationException();
}
 
示例19
@Override
public ProjectRequest waitUntilReady(OkHttpClient client, Config config, String namespace, ProjectRequest item, long amount, TimeUnit timeUnit) throws InterruptedException {
  throw new UnsupportedOperationException();
}
 
示例20
@Override
public ProjectRequest waitUntilCondition(OkHttpClient client, Config config, String namespace, ProjectRequest item, Predicate<ProjectRequest> condition, long amount, TimeUnit timeUnit) throws InterruptedException {
  throw new UnsupportedOperationException();
}