io.fabric8.kubernetes.api.model.ReplicationControllerList Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.ReplicationControllerList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TeiidOpenShiftClient.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private static Long getDeployedRevision(DeploymentConfig dc, Long defaultNumber, final OpenShiftClient client) {
    long latestVersion = dc.getStatus().getLatestVersion().longValue();
    ReplicationControllerList list = client.replicationControllers().inNamespace(dc.getMetadata().getNamespace())
            .withLabel("application", dc.getMetadata().getName()).list();

    for (ReplicationController rc : list.getItems()) {
        String version = rc.getMetadata().getAnnotations().get("openshift.io/deployment-config.latest-version");
        if (version != null && Long.parseLong(version) == latestVersion) {
            String deployedVersion = rc.getSpec().getTemplate().getMetadata().getLabels().get(DEPLOYMENT_VERSION_LABEL);
            if (deployedVersion != null) {
                try {
                    return Long.parseLong(deployedVersion);
                } catch (NumberFormatException e) {
                    LOG.error("unexpected value for deployment-version", e);
                }
            }
        }
    }
    return defaultNumber;
}
 
Example #2
Source File: ReplicationControllerDelete.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    super.initializeUI(builder);

    // populate autocompletion options
    replicationControllerId.setCompleter(new UICompleter<String>() {
        @Override
        public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
            List<String> list = new ArrayList<String>();
            ReplicationControllerList replicationControllers = getKubernetes().replicationControllers().inNamespace(getNamespace()).list();
            if (replicationControllers != null) {
                List<ReplicationController> items = replicationControllers.getItems();
                if (items != null) {
                    for (ReplicationController item : items) {
                        String id = KubernetesHelper.getName(item);
                        list.add(id);
                    }
                }
            }
            Collections.sort(list);
            return list;
        }
    });

    builder.add(replicationControllerId);
}
 
Example #3
Source File: ReplicationControllerTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testList() {
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers").andReturn(200, new ReplicationControllerListBuilder().build()).once();
 server.expect().withPath("/api/v1/namespaces/ns1/replicationcontrollers").andReturn(200,  new ReplicationControllerListBuilder()
    .addNewItem().and()
    .addNewItem().and().build())
    .once();

  KubernetesClient client = server.getClient();
  ReplicationControllerList replicationControllerList = client.replicationControllers().list();
  assertNotNull(replicationControllerList);
  assertEquals(0, replicationControllerList.getItems().size());

  replicationControllerList = client.replicationControllers().inNamespace("ns1").list();
  assertNotNull(replicationControllerList);
  assertEquals(2, replicationControllerList.getItems().size());
}
 
Example #4
Source File: SparkClusterOperator.java    From spark-operator with Apache License 2.0 5 votes vote down vote up
private Map<String, Integer> getActual() {
    MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> aux1 =
            client.replicationControllers();
    FilterWatchListMultiDeletable<ReplicationController, ReplicationControllerList, Boolean, Watch, Watcher<ReplicationController>> aux2 =
            "*".equals(namespace) ? aux1.inAnyNamespace() : aux1.inNamespace(namespace);
    Map<String, String> labels =new HashMap<>(2);
    labels.put(prefix + OPERATOR_KIND_LABEL, entityName);
    labels.put(prefix + OPERATOR_RC_TYPE_LABEL, "worker");
    List<ReplicationController> workerRcs = aux2.withLabels(labels).list().getItems();
    Map<String, Integer> retMap = workerRcs
            .stream()
            .collect(Collectors.toMap(rc -> rc.getMetadata().getLabels().get(prefix + entityName),
                    rc -> rc.getSpec().getReplicas()));
    return retMap;
}
 
Example #5
Source File: ReplicationControllersList.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
private void printReplicationControllers(ReplicationControllerList replicationControllers, PrintStream out) {
    TablePrinter table = new TablePrinter();
    table.columns("id", "labels", "replicas", "replica selector");
    List<ReplicationController> items = replicationControllers.getItems();
    if (items == null) {
        items = Collections.EMPTY_LIST;
    }
    Filter<ReplicationController> filter = KubernetesHelper.createReplicationControllerFilter(filterText.getValue());
    for (ReplicationController item : items) {
        if (filter.matches(item)) {
            String id = KubernetesHelper.getName(item);
            String labels = KubernetesHelper.toLabelsString(item.getMetadata().getLabels());
            Integer replicas = null;
            ReplicationControllerSpec desiredState = item.getSpec();
            ReplicationControllerStatus currentState = item.getStatus();
            String selector = null;
            if (desiredState != null) {
                selector = KubernetesHelper.toLabelsString(desiredState.getSelector());
            }
            if (currentState != null) {
                replicas = currentState.getReplicas();
            }
            table.row(id, labels, toPositiveNonZeroText(replicas), selector);
        }
    }
    table.print();
}
 
Example #6
Source File: ReplicationControllersList.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
@Override
public Result execute(UIExecutionContext uiExecutionContext) throws Exception {
    ReplicationControllerList replicationControllers = getKubernetes().replicationControllers().inNamespace(getNamespace()).list();
    printReplicationControllers(replicationControllers, System.out);
    return null;
}
 
Example #7
Source File: ReplicationControllerRollingUpdater.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Operation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> resources() {
  return new ReplicationControllerOperationsImpl(client, config);
}
 
Example #8
Source File: ReplicationControllerOperationsImpl.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public ReplicationControllerOperationsImpl(RollingOperationContext context) {
  super(context.withPlural("replicationcontrollers"));
  this.type = ReplicationController.class;
  this.listType = ReplicationControllerList.class;
  this.doneableType = DoneableReplicationController.class;
}
 
Example #9
Source File: ReplicationControllerOperationsImpl.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public RollingUpdater<ReplicationController, ReplicationControllerList, DoneableReplicationController> getRollingUpdater(long rollingTimeout, TimeUnit rollingTimeUnit) {
  return new ReplicationControllerRollingUpdater(client, config, namespace, rollingTimeUnit.toMillis(rollingTimeout), config.getLoggingInterval());
}
 
Example #10
Source File: AutoAdaptableKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> replicationControllers() {
  return delegate.replicationControllers();
}
 
Example #11
Source File: DefaultKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> replicationControllers() {
  return new ReplicationControllerOperationsImpl(httpClient, getConfiguration());
}
 
Example #12
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> replicationControllers() {
  return delegate.replicationControllers();
}
 
Example #13
Source File: KubernetesClient.java    From kubernetes-client with Apache License 2.0 2 votes vote down vote up
/**
 * API entrypoint for ReplicationController related operations. ReplicationController (core/v1)
 *
 * @return MixedOperation object for ReplicationController related operations.
 */
MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> replicationControllers();