use of io.fabric8.kubernetes.api.model.KubernetesResource in project fabric8-maven-plugin by fabric8io.
the class AppCatalogMojo method populateAnnotationsFromResources.
private void populateAnnotationsFromResources(KubernetesResource resource, Map<String, String> annotations) {
if (resource instanceof KubernetesList) {
KubernetesList list = (KubernetesList) resource;
List<HasMetadata> items = list.getItems();
if (items != null) {
for (HasMetadata item : items) {
populateAnnotationsForEntity(item, annotations);
}
}
} else if (resource instanceof HasMetadata) {
HasMetadata entity = (HasMetadata) resource;
populateAnnotationsForEntity(entity, annotations);
}
}
use of io.fabric8.kubernetes.api.model.KubernetesResource in project fabric8 by fabric8io.
the class KubernetesProviderProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
CompilationTaskFactory compilationTaskFactory = new CompilationTaskFactory(processingEnv);
Set<TypeElement> providers = new HashSet<>();
// 1st pass collect classes to compile.
for (Element element : roundEnv.getElementsAnnotatedWith(KubernetesProvider.class)) {
providers.add(getClassElement(element));
}
if (providers.isEmpty()) {
return true;
}
StringWriter writer = new StringWriter();
try {
Callable<Boolean> compileTask = compilationTaskFactory.create(providers, writer);
if (!compileTask.call()) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to compile provider classes. See output below.");
return false;
}
} catch (Exception e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Error to compile provider classes, due to: " + e.getMessage() + ". See output below.");
return false;
} finally {
String output = writer.toString();
if (Strings.isNullOrBlank(output)) {
output = "success";
}
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Fabric8 model generator compiler output:" + output);
}
// 2nd pass generate json.
Map<String, Set> providedMap = new HashMap<>();
for (Element element : roundEnv.getElementsAnnotatedWith(KubernetesProvider.class)) {
try {
if (element instanceof ExecutableElement) {
Set provided = getProvidedSet(providedMap, element);
ExecutableElement methodElement = (ExecutableElement) element;
String methodName = methodElement.getSimpleName().toString();
TypeElement classElement = getClassElement(element);
Class<?> cls = Class.forName(classElement.getQualifiedName().toString());
Object instance = cls.newInstance();
Method providerMethod = instance.getClass().getDeclaredMethod(methodName);
if (providerMethod != null) {
providerMethod.setAccessible(true);
provided.add(providerMethod.invoke(instance));
}
}
} catch (Exception ex) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Error creating Kubernetes configuration.");
}
}
for (Map.Entry<String, Set> entry : providedMap.entrySet()) {
KubernetesResource answer;
try {
answer = (KubernetesResource) KubernetesHelper.combineJson(entry.getValue().toArray());
generateKubernetesManifest(entry.getKey(), answer);
} catch (Exception e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to combine provider items");
return false;
}
}
return true;
}
Aggregations