コード例 #1
0
func handleCreate(receptorClient receptor.Client) {
	newProcessGuid, err := uuid.NewV4()
	if err != nil {
		logger.Error("failed-generate-guid", err)
		return
	}
	route := tcpRoute{
		ExternalPort:  uint16(*externalPort),
		ContainerPort: uint16(*containerPort),
	}
	routes := []tcpRoute{route}
	data, err := json.Marshal(routes)
	if err != nil {
		logger.Error("failed-to-marshal", err)
		return
	}
	routingInfo := json.RawMessage(data)
	lrp := receptor.DesiredLRPCreateRequest{
		ProcessGuid: newProcessGuid.String(),
		LogGuid:     "log-guid",
		Domain:      "ge",
		Instances:   1,
		Setup: &models.SerialAction{
			Actions: []models.Action{
				&models.RunAction{
					Path: "sh",
					User: "******",
					Args: []string{
						"-c",
						"curl https://s3.amazonaws.com/router-release-blobs/tcp-sample-receiver.linux -o /tmp/tcp-sample-receiver && chmod +x /tmp/tcp-sample-receiver",
					},
				},
			},
		},
		Action: &models.ParallelAction{
			Actions: []models.Action{
				&models.RunAction{
					Path: "sh",
					User: "******",
					Args: []string{
						"-c",
						fmt.Sprintf("/tmp/tcp-sample-receiver -address 0.0.0.0:%d -serverId %s", *containerPort, *serverId),
						// fmt.Sprintf("nc -l -k %d > /tmp/output", *containerPort),
					},
				},
			},
		},
		Monitor: &models.RunAction{
			Path: "sh",
			User: "******",
			Args: []string{
				"-c",
				fmt.Sprintf("nc -z 0.0.0.0 %d", *containerPort),
			}},
		StartTimeout: 60,
		RootFS:       "preloaded:cflinuxfs2",
		MemoryMB:     128,
		DiskMB:       128,
		Ports:        []uint16{uint16(*containerPort)},
		Routes: receptor.RoutingInfo{
			"tcp-router": &routingInfo,
		},
		EgressRules: []models.SecurityGroupRule{
			{
				Protocol:     models.TCPProtocol,
				Destinations: []string{"0.0.0.0-255.255.255.255"},
				Ports:        []uint16{80, 443},
			},
			{
				Protocol:     models.UDPProtocol,
				Destinations: []string{"0.0.0.0/0"},
				PortRange: &models.PortRange{
					Start: 53,
					End:   53,
				},
			},
		},
	}
	err = receptorClient.CreateDesiredLRP(lrp)
	if err != nil {
		logger.Error("failed-create", err, lager.Data{"LRP": lrp})
	} else {
		fmt.Printf("Successfully created LRP with process guid %s\n", newProcessGuid)
	}
}
コード例 #2
0
			receptorClient receptor.Client
			processGuid    string
		)

		BeforeEach(func() {

			receptorClient = receptor.NewClient(routerApiConfig.DiegoAPIURL)

			externalPort = 62000 + GinkgoParallelNode()
			sampleReceiverPort1 = 8000 + GinkgoParallelNode()
			serverId1 = fmt.Sprintf("serverId-%d", GinkgoParallelNode())

			lrp := helpers.CreateDesiredLRP(logger,
				uint16(externalPort), uint16(sampleReceiverPort1), serverId1, 1)

			err := receptorClient.CreateDesiredLRP(lrp)
			Expect(err).ShouldNot(HaveOccurred())
			processGuid = lrp.ProcessGuid
		})

		AfterEach(func() {
			err := receptorClient.DeleteDesiredLRP(processGuid)
			Expect(err).ShouldNot(HaveOccurred())
		})

		It("receives TCP traffic on desired external port", func() {
			verifyConnection(externalPort, serverId1)

			By("updating LRP with new external port it receives traffic on new external port")
			externalPort = 63000 + GinkgoParallelNode()
			updatedLrp := helpers.UpdateDesiredLRP(uint16(externalPort),