io.fabric8.kubernetes.api.builder.VisitableBuilder Java Examples

The following examples show how to use io.fabric8.kubernetes.api.builder.VisitableBuilder. 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: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Override
public List<HasMetadata> get() {
    if (fromServer) {
        List<HasMetadata> result = new ArrayList<>();
        for (HasMetadata meta : acceptVisitors(asHasMetadata(item, true), visitors)) {
            ResourceHandler<HasMetadata, ? extends VisitableBuilder> h = handlerOf(meta);
            HasMetadata reloaded = h.reload(client, config, meta.getMetadata().getNamespace(), meta);
            if (reloaded != null) {
                HasMetadata edited = reloaded;
                //Let's apply any visitor that might have been specified.
                for (Visitor v : visitors) {
                    h.edit(edited).accept(v).build();
                }
                result.add(reloaded);
            }
        }
        return result;
    } else {
        return acceptVisitors(asHasMetadata(item, true), visitors);
    }
}
 
Example #2
Source File: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Override
public HasMetadata get() {
  if (fromServer) {
    HasMetadata meta = acceptVisitors(asHasMetadata(item), visitors);
    ResourceHandler<HasMetadata, ? extends VisitableBuilder> h = handlerOf(meta);
    HasMetadata reloaded = h.reload(client, config, meta.getMetadata().getNamespace(), meta);
    if (reloaded != null) {
      HasMetadata edited = reloaded;
      //Let's apply any visitor that might have been specified.
      for (Visitor v : visitors) {
        edited = h.edit(edited).accept(v).build();
      }
      return edited;
    }
    return null;
  } else {
    return acceptVisitors(asHasMetadata(item), visitors);
  }
}
 
Example #3
Source File: NamedTaskDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(VisitableBuilder builder) {
  Optional<ObjectMeta> objectMeta = getMetadata(builder);
  if (!objectMeta.isPresent()) {
    return;
  }
  if (Strings.isNullOrEmpty(taskName)
      || objectMeta.map(m -> m.getName()).filter(s -> s.equals(taskName)).isPresent()) {
    builder.accept(taskVisitor);
  }
}
 
Example #4
Source File: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
private static List<HasMetadata> acceptVisitors(List<HasMetadata> list, List<Visitor> visitors) {
  List<HasMetadata> result = new ArrayList<>();
  for (HasMetadata item : list) {
    ResourceHandler<HasMetadata, HasMetadataVisitiableBuilder> h = handlerOf(item);
    VisitableBuilder<HasMetadata, ?> builder = h.edit(item);

    //Let's apply any visitor that might have been specified.
    for (Visitor v : visitors) {
      builder.accept(v);
    }
    result.add(builder.build());
  }
  return result;
}
 
Example #5
Source File: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
private static HasMetadata acceptVisitors(HasMetadata item, List<Visitor> visitors) {
  ResourceHandler<HasMetadata, HasMetadataVisitiableBuilder> h = handlerOf(item);
  VisitableBuilder<HasMetadata, ?> builder = h.edit(item);

  //Let's apply any visitor that might have been specified.
  for (Visitor v : visitors) {
    builder.accept(v);
  }
  return builder.build();
}
 
Example #6
Source File: KubernetesListOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
private <T extends HasMetadata, V extends VisitableBuilder<T, V>> T create(T resource) {
  ResourceHandler<T, V> handler = Handlers.get(resource.getKind(), resource.getApiVersion());
  if (handler != null) {
    return handler.create(client, config, namespace, resource);
  }
  throw new IllegalStateException("Could not find handler");
}
 
Example #7
Source File: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
private static List<HasMetadata> acceptVisitors(List<HasMetadata> list, List<Visitor> visitors) {
    List<HasMetadata> result = new ArrayList<>();
    for (HasMetadata item : list) {
        ResourceHandler<HasMetadata, HasMetadataVisitiableBuilder> h = handlerOf(item);
        VisitableBuilder<HasMetadata, ?> builder = h.edit(item);

        //Let's apply any visitor that might have been specified.
        for (Visitor v : visitors) {
            builder.accept(v);
        }
        result.add(builder.build());
    }
    return result;
}
 
Example #8
Source File: Metadata.java    From dekorate with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@link Predicate} that checks that a resource builder doesn't match the name and kind.
 * @param kind The specified kind.
 * @param name The specified name.
 * @return The predicate.
 */
public static Predicate<VisitableBuilder<? extends HasMetadata, ?>> matching(String apiVersion, String kind, String name) {
  return new Predicate<VisitableBuilder<? extends HasMetadata, ?>>() {
    @Override
    public Boolean apply(VisitableBuilder<? extends HasMetadata, ?> builder) {
      HasMetadata item = builder.build();
      ObjectMeta metadata = item.getMetadata();
      return apiVersion.equals(item.getApiVersion()) &&
        kind != null && kind.equals(item.getKind()) &&
        name != null && name.equals(metadata.getName());
    }
  };
}
 
Example #9
Source File: NamedPipelineDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(VisitableBuilder builder) {
  Optional<ObjectMeta> objectMeta = getMetadata(builder);
  if (!objectMeta.isPresent()) {
    return;
  }
  if (Strings.isNullOrEmpty(pipelineName)
      || objectMeta.map(m -> m.getName()).filter(s -> s.equals(pipelineName)).isPresent()) {
    builder.accept(pipelineVisitor);
  }
}
 
Example #10
Source File: NamedResourceDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(VisitableBuilder builder) {
  Optional<ObjectMeta> objectMeta = getMetadata(builder);
  if (!objectMeta.isPresent()) {
    return;
  }
  if (Strings.isNullOrEmpty(name)) {
    builder.accept(visitor.withMetadata(objectMeta.get()));
  } else if (objectMeta.map(m -> m.getName()).filter(s -> s.equals(name)).isPresent()) {
    builder.accept(visitor.withMetadata(objectMeta.get()));
  }
}
 
Example #11
Source File: ApplicationContainerDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(VisitableBuilder builder) {
  Optional<ObjectMeta> objectMeta = getMetadata(builder);
  if (!objectMeta.isPresent()) {
    return;
  }
  if (Strings.isNullOrEmpty(deploymentName) || objectMeta.map(m -> m.getName()).filter(s -> s.equals(deploymentName)).isPresent()) {
    builder.accept(deploymentVisitor);
  }
}
 
Example #12
Source File: TektonStepDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(VisitableBuilder builder) {
  Optional<ObjectMeta> objectMeta = getMetadata(builder);
  if (!objectMeta.isPresent()) {
    return;
  }
  if (Strings.isNullOrEmpty(taskName) || objectMeta.map(m -> m.getName()).filter(s -> s.equals(taskName)).isPresent()) {
    builder.accept(deploymentVisitor);
  }
}
 
Example #13
Source File: Handlers.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public static <T extends HasMetadata, V extends VisitableBuilder<T, V>> ResourceHandler<T, V> get(String kind, String apiVersion, ClassLoader classLoader) {
 return get(new ResourceHandler.Key(kind.toLowerCase(Locale.ROOT), apiVersion), classLoader);
}
 
Example #14
Source File: Handlers.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public static <T extends HasMetadata, V extends VisitableBuilder<T, V>> ResourceHandler<T, V> get(String kind, String apiVersion) {
  return get(kind, apiVersion, Thread.currentThread().getContextClassLoader());
}
 
Example #15
Source File: Handlers.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public static <T extends HasMetadata, V extends VisitableBuilder<T, V>> void unregister(ResourceHandler<T,V> handler) {
  RESOURCE_HANDLER_MAP.remove(new ResourceHandler.Key(handler.getKind().toLowerCase(Locale.ROOT), handler.getApiVersion()));
}
 
Example #16
Source File: Handlers.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public static <T extends HasMetadata, V extends VisitableBuilder<T, V>> void register(ResourceHandler<T,V> handler) {
  RESOURCE_HANDLER_MAP.put(new ResourceHandler.Key(handler.getKind().toLowerCase(Locale.ROOT), handler.getApiVersion()), handler);
}
 
Example #17
Source File: Handlers.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public static <T extends HasMetadata, V extends VisitableBuilder<T, V>> ResourceHandler<T, V> get(ResourceHandler.Key key) {
  return get(key, Thread.currentThread().getContextClassLoader());
}
 
Example #18
Source File: DefaultConfiguration.java    From dekorate with Apache License 2.0 4 votes vote down vote up
public DefaultConfiguration(VisitableBuilder<C, ?> builder) {
  super(builder);
}
 
Example #19
Source File: ConfigurationSupplier.java    From dekorate with Apache License 2.0 4 votes vote down vote up
public ConfigurationSupplier (VisitableBuilder<C, ?> builder, boolean explicit) {
  this.builder = builder; 
  this.explicit = explicit;
}
 
Example #20
Source File: ConfigurationSupplier.java    From dekorate with Apache License 2.0 4 votes vote down vote up
public ConfigurationSupplier (VisitableBuilder<C, ?> builder) {
  this(builder, false);
}
 
Example #21
Source File: PropertyConfiguration.java    From dekorate with Apache License 2.0 4 votes vote down vote up
public PropertyConfiguration(VisitableBuilder<C, ?> builder) {
  super(builder, true);
}
 
Example #22
Source File: AnnotationConfiguration.java    From dekorate with Apache License 2.0 4 votes vote down vote up
public AnnotationConfiguration(VisitableBuilder<C, ?> builder) {
  super(builder, true);
}
 
Example #23
Source File: Metadata.java    From dekorate with Apache License 2.0 2 votes vote down vote up
/**
 * Create a {@link Predicate} that checks that a resource builder doesn't match the name and kind.
 * @param HasMetadata The specified resource.
 * @return The predicate.
 */
public static Predicate<VisitableBuilder<? extends HasMetadata, ?>> matching(HasMetadata candidate) {
  return matching(candidate.getApiVersion(), candidate.getKind(), candidate.getMetadata().getName());
}