use of io.fabric8.kubernetes.api.model.KubernetesResourceList in project kie-wb-common by kiegroup.
the class OpenShiftTemplate method load.
@SuppressWarnings({ "rawtypes", "unchecked" })
private Template load(InputStream templateStream) {
String generatedName = Utils.randomString("template-", 10);
Template temp = null;
Object item = Serialization.unmarshal(templateStream);
if (item instanceof Template) {
temp = (Template) item;
} else if (item instanceof HasMetadata) {
HasMetadata h = (HasMetadata) item;
temp = new TemplateBuilder().withNewMetadata().withName(generatedName).withNamespace(h != null && h.getMetadata() != null ? h.getMetadata().getNamespace() : null).endMetadata().withObjects(h).build();
} else if (item instanceof KubernetesResourceList) {
List<HasMetadata> list = ((KubernetesResourceList<HasMetadata>) item).getItems();
temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects(list.toArray(new HasMetadata[list.size()])).build();
} else if (item instanceof HasMetadata[]) {
temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects((HasMetadata[]) item).build();
} else if (item instanceof Collection) {
List<HasMetadata> items = new ArrayList<>();
for (Object o : (Collection) item) {
if (o instanceof HasMetadata) {
items.add((HasMetadata) o);
}
}
temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects(items.toArray(new HasMetadata[items.size()])).build();
}
return temp;
}
Aggregations