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

com.github.narcissujsk.openstackjsk.openstack.networking.domain.NeutronRouter Maven / Gradle / Ivy

The newest version!
package com.github.narcissujsk.openstackjsk.openstack.networking.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.github.narcissujsk.openstackjsk.model.common.builder.ResourceBuilder;
import com.github.narcissujsk.openstackjsk.model.network.ExternalGateway;
import com.github.narcissujsk.openstackjsk.model.network.HostRoute;
import com.github.narcissujsk.openstackjsk.model.network.Router;
import com.github.narcissujsk.openstackjsk.model.network.State;
import com.github.narcissujsk.openstackjsk.model.network.builder.RouterBuilder;
import com.github.narcissujsk.openstackjsk.openstack.common.ListResult;

import java.util.List;

/**
 * A router is used to interconnect subnets and forward traffic among them. Another feature of the router is to NAT internal traffic to external networks.
 *
 * @author Jeremy Unruh
 */
@JsonRootName("router")
public class NeutronRouter implements Router {

    private static final long serialVersionUID = 1L;

    @JsonProperty("id")
    private String id;

    @JsonProperty("name")
    private String name;

    @JsonProperty("status")
    private State status;

    @JsonProperty("external_gateway_info")
    private NeutronExternalGateway externalGatewayInfo;

    @JsonProperty("admin_state_up")
    private Boolean adminStateUp;

    @JsonProperty("tenant_id")
    private String tenantId;

    @JsonProperty("routes")
    private List routes;

    @JsonProperty("distributed")
    private Boolean distributed;

    public static RouterBuilder builder() {
        return new RouterConcreteBuilder();
    }

    @Override
    public RouterBuilder toBuilder() {
        return new RouterConcreteBuilder(this);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getId() {
        return id;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getName() {
        return name;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getTenantId() {
        return tenantId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setId(String id) {
        this.id = id;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setName(String name) {
        this.name = name;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List getRoutes() {
        return routes;
    }

    /**
     * {@inheritDoc}
     */
    @JsonIgnore
    @Override
    public boolean isAdminStateUp() {
        return (adminStateUp != null) ? adminStateUp : false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public State getStatus() {
        return status;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ExternalGateway getExternalGatewayInfo() {
        return externalGatewayInfo;
    }

    @Override
    public Boolean getDistributed() {
        return distributed;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).omitNullValues()
                .add("id", id).add("name", name).add("tenantId", tenantId).add("admin_state_up", adminStateUp)
                .add("external_gateway_info", externalGatewayInfo).add("routes", routes)
                .add("distributed", distributed)
                .addValue("\n")
                .toString();
    }

    /**
     * {@inheritDoc}
     */
		@Override
		public int hashCode() {
			return java.util.Objects.hash(id, name, status, tenantId, adminStateUp,
							externalGatewayInfo, routes);
		}

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
          return true;
        }

        if (obj instanceof NeutronRouter) {
            NeutronRouter that = (NeutronRouter) obj;
            if (java.util.Objects.equals(id, that.id) &&
                    java.util.Objects.equals(name, that.name) &&
                    java.util.Objects.equals(status, that.status) &&
                    java.util.Objects.equals(tenantId, that.tenantId) &&
                    java.util.Objects.equals(adminStateUp, that.adminStateUp) &&
                    java.util.Objects.equals(externalGatewayInfo, that.externalGatewayInfo) &&
                    java.util.Objects.equals(routes, that.routes)) {
              return true;
            }
        }
        return false;
    }

    public static class Routers extends ListResult {

        private static final long serialVersionUID = 1L;

        @JsonProperty("routers")
        private List routers;

        @Override
        protected List value() {
            return routers;
        }
    }

    public static class RouterConcreteBuilder extends ResourceBuilder implements RouterBuilder {

        private NeutronRouter m;

        RouterConcreteBuilder() {
            this(new NeutronRouter());
        }

        RouterConcreteBuilder(NeutronRouter m) {
            this.m = m;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder adminStateUp(boolean isAdminStateUp) {
            m.adminStateUp = isAdminStateUp;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder externalGateway(String networkId) {
            return externalGateway(networkId, null);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder externalGateway(String networkId, Boolean enableSNAT) {
            m.externalGatewayInfo = new NeutronExternalGateway(networkId, enableSNAT);
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder externalGateway(ExternalGateway externalGateway) {
            m.externalGatewayInfo = (NeutronExternalGateway) externalGateway;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder clearExternalGateway() {
            m.externalGatewayInfo = new NeutronExternalGateway();
            return this;
        }


        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder route(String destination, String nexthop) {
            if (m.routes == null)
                m.routes = Lists.newArrayList();
            m.routes.add(new NeutronHostRoute(destination, nexthop));
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder noRoutes() {
            m.routes = Lists.newArrayList();
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        protected Router reference() {
            return m;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public Router build() {
            return m;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder from(Router in) {
            m = (NeutronRouter) in;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public RouterBuilder distributed(Boolean distributed) {
            m.distributed = distributed;
            return this;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy