func TestAddControlPlaneEndpoints(t *testing.T) { agent := &HostAgent{} agent.master = "127.0.0.1:0" agent.uiport = ":443" endpoints := make(map[string][]dao.ApplicationEndpoint) consumer_endpoint := dao.ApplicationEndpoint{} consumer_endpoint.ServiceID = "controlplane_consumer" consumer_endpoint.Application = "controlplane_consumer" consumer_endpoint.ContainerIP = "127.0.0.1" consumer_endpoint.ContainerPort = 8443 consumer_endpoint.ProxyPort = 8444 consumer_endpoint.HostPort = 8443 consumer_endpoint.HostIP = "127.0.0.1" consumer_endpoint.Protocol = "tcp" controlplane_endpoint := dao.ApplicationEndpoint{} controlplane_endpoint.ServiceID = "controlplane" controlplane_endpoint.Application = "controlplane" controlplane_endpoint.ContainerIP = "127.0.0.1" controlplane_endpoint.ContainerPort = 443 controlplane_endpoint.ProxyPort = 443 controlplane_endpoint.HostPort = 443 controlplane_endpoint.HostIP = "127.0.0.1" controlplane_endpoint.Protocol = "tcp" agent.addControlPlaneEndpoint(endpoints) agent.addControlPlaneConsumerEndpoint(endpoints) if _, ok := endpoints["tcp:8444"]; !ok { t.Fatalf(" mapping failed missing key[\"tcp:8444\"]") } if _, ok := endpoints["tcp:443"]; !ok { t.Fatalf(" mapping failed missing key[\"tcp:443\"]") } if len(endpoints["tcp:8444"]) != 1 { t.Fatalf(" mapping failed len(\"tcp:8444\"])=%d expected 1", len(endpoints["tcp:8444"])) } if len(endpoints["tcp:443"]) != 1 { t.Fatalf(" mapping failed len(\"tcp:443\"])=%d expected 1", len(endpoints["tcp:443"])) } if endpoints["tcp:8444"][0] != consumer_endpoint { t.Fatalf(" mapping failed %+v expected %+v", endpoints["tcp:8444"][0], consumer_endpoint) } if endpoints["tcp:443"][0] != controlplane_endpoint { t.Fatalf(" mapping failed %+v expected %+v", endpoints["tcp:443"][0], controlplane_endpoint) } }
// addControlPlaneConsumerEndpoint adds an application endpoint mapping for the master control center api func (a *HostAgent) addControlPlaneConsumerEndpoint(endpoints map[string][]dao.ApplicationEndpoint) { key := "tcp:8444" endpoint := dao.ApplicationEndpoint{} endpoint.ServiceID = "controlplane_consumer" endpoint.Application = "controlplane_consumer" endpoint.ContainerIP = "127.0.0.1" endpoint.ContainerPort = 8443 endpoint.ProxyPort = 8444 endpoint.HostPort = 8443 endpoint.HostIP = strings.Split(a.master, ":")[0] endpoint.Protocol = "tcp" a.addEndpoint(key, endpoint, endpoints) }
// addControlPlaneEndpoint adds an application endpoint mapping for the master control center api func (a *HostAgent) addControlPlaneEndpoint(endpoints map[string][]dao.ApplicationEndpoint) { key := "tcp" + a.uiport endpoint := dao.ApplicationEndpoint{} endpoint.ServiceID = "controlplane" endpoint.Application = "controlplane" endpoint.ContainerIP = "127.0.0.1" port, err := strconv.Atoi(a.uiport[1:]) if err != nil { glog.Errorf("Unable to interpret ui port.") return } endpoint.ContainerPort = uint16(port) endpoint.ProxyPort = uint16(port) endpoint.HostPort = uint16(port) endpoint.HostIP = strings.Split(a.master, ":")[0] endpoint.Protocol = "tcp" a.addEndpoint(key, endpoint, endpoints) }