All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.openshift.internal.restclient.api.models.Endpoints Maven / Gradle / Ivy

The newest version!
/******************************************************************************* 
 * Copyright (c) 2016 Red Hat, Inc. 
 * Distributed under license by Red Hat, Inc. All rights reserved. 
 * This program is made available under the terms of the 
 * Eclipse Public License v1.0 which accompanies this distribution, 
 * and is available at http://www.eclipse.org/legal/epl-v10.html 
 * 
 * Contributors: 
 * Red Hat, Inc. - initial API and implementation 
 ******************************************************************************/

package com.openshift.internal.restclient.api.models;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.jboss.dmr.ModelNode;

import com.openshift.internal.restclient.model.KubernetesResource;
import com.openshift.internal.restclient.model.ModelNodeAdapter;
import com.openshift.internal.restclient.model.ObjectReference;
import com.openshift.internal.util.JBossDmrExtentions;
import com.openshift.restclient.IClient;
import com.openshift.restclient.api.models.IEndpoints;
import com.openshift.restclient.model.IObjectReference;

public class Endpoints extends KubernetesResource implements IEndpoints {

    public Endpoints(ModelNode node, IClient client, Map overrideProperties) {
        super(node, client, overrideProperties);
    }

    @Override
    public List getSubSets() {
        List root = get("subsets").asList();
        ArrayList subsets = new ArrayList(root.size());
        for (ModelNode n : root) {
            subsets.add(new EndpointSubset(n, getPropertyKeys()));
        }
        return subsets;
    }

    private static class EndpointSubset extends ModelNodeAdapter implements IEndpointSubset {

        protected EndpointSubset(ModelNode node, Map propertyKeys) {
            super(node, propertyKeys);
        }

        @Override
        public List getAddresses() {
            List root = JBossDmrExtentions.get(getNode(), getPropertyKeys(), "addresses").asList();
            ArrayList addresses = new ArrayList(root.size());
            for (ModelNode n : root) {
                addresses.add(new EndpointAddress(n, getPropertyKeys()));
            }
            return addresses;
        }

        @Override
        public List getNotReadyAddresses() {
            List root = JBossDmrExtentions.get(getNode(), getPropertyKeys(), "notreadyaddresses").asList();
            ArrayList addresses = new ArrayList(root.size());
            for (ModelNode n : root) {
                addresses.add(new EndpointAddress(n, getPropertyKeys()));
            }
            return addresses;
        }

        @Override
        public List getPorts() {
            List root = JBossDmrExtentions.get(getNode(), getPropertyKeys(), PORTS).asList();
            ArrayList ports = new ArrayList(root.size());
            for (ModelNode n : root) {
                ports.add(new EndpointPort(n, getPropertyKeys()));
            }
            return ports;
        }

    }

    private static class EndpointAddress extends ModelNodeAdapter implements IEndpointAddress {

        private static final String TARGET_REF = "targetRef";

        protected EndpointAddress(ModelNode node, Map propertyKeys) {
            super(node, propertyKeys);
        }

        @Override
        public String getIP() {
            return JBossDmrExtentions.asString(getNode(), getPropertyKeys(), "ip");
        }

        @Override
        public String getHostName() {
            return JBossDmrExtentions.asString(getNode(), getPropertyKeys(), "hostname");
        }

        @Override
        public String getNodeName() {
            return JBossDmrExtentions.asString(getNode(), getPropertyKeys(), "nodeName");
        }

        @Override
        public String getName() {
            return JBossDmrExtentions.asString(getNode(), getPropertyKeys(), NAME);
        }

        @Override
        public IObjectReference getTargetRef() {
            if (getNode().has(JBossDmrExtentions.getPath(getPropertyKeys(), TARGET_REF))) {
                ModelNode node = JBossDmrExtentions.get(getNode(), getPropertyKeys(), TARGET_REF);
                return new ObjectReference(node);
            }
            return null;
        }

    }

    private static class EndpointPort extends ModelNodeAdapter implements IEndpointPort {

        protected EndpointPort(ModelNode node, Map propertyKeys) {
            super(node, propertyKeys);
        }

        @Override
        public String getName() {
            return JBossDmrExtentions.asString(getNode(), getPropertyKeys(), NAME);
        }

        @Override
        public int getPort() {
            return JBossDmrExtentions.asInt(getNode(), getPropertyKeys(), "port");
        }

        @Override
        public String getProtocol() {
            return JBossDmrExtentions.asString(getNode(), getPropertyKeys(), PROTOCOL);
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy