Search in sources :

Example 1 with KubernetesResourceList

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;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) TemplateBuilder(io.fabric8.openshift.api.model.TemplateBuilder) KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DoneableTemplate(io.fabric8.openshift.api.model.DoneableTemplate) Template(io.fabric8.openshift.api.model.Template)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 KubernetesResourceList (io.fabric8.kubernetes.api.model.KubernetesResourceList)1 DoneableTemplate (io.fabric8.openshift.api.model.DoneableTemplate)1 Template (io.fabric8.openshift.api.model.Template)1 TemplateBuilder (io.fabric8.openshift.api.model.TemplateBuilder)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1