func newDesiredLRP(guid string) (*models.DesiredLRP, error) {
	myRouterJSON := json.RawMessage(`[{"hostnames":["dora.bosh-lite.com"],"port":8080}]`)
	myRouterJSON2 := json.RawMessage(`{"container_port":2222,"host_fingerprint":"44:00:2b:21:19:1a:42:ab:54:2f:c3:9d:97:d6:c8:0f","private_key":"-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQCu4BiQh96+AvbYHDxRhfK9Scsl5diUkb/LIbe7Hx7DZg8iTxvr\nkw+de3i1TZG3wH02bdReBnCXrN/u59q0qqsz8ge71BFqnSF0dJaSmXhWizN0NQEy\n5u4WyqM4WJTzUGFnofJxnwFArHBT6QEtDjqCJxyggjuBrF60x3HtSfp4gQIDAQAB\nAoGBAJp/SbSHFXbxz3tmlrO/j5FEHMJCqnG3wqaIB3a+K8Od60j4c0ZRCr6rUx16\nhn69BOKNbc4UCm02QjEjjcmH7u/jLflvKLR/EeEXpGpAd7i3b5bqNn98PP+KwnbS\nPxbot37KErdwLnlF8QYFZMeqHiXQG8nO1nqroiX+fVUDtipBAkEAx8nDxLet6ObJ\nWzdR/8dSQ5qeCqXlfX9PFN6JHtw/OBZjRP5jc2cfGXAAB2h7w5XBy0tak1+76v+Y\nTrdq/rqAdQJBAOAT7W0FpLAZEJusY4sXkhZJvGO0e9MaOdYx53Z2m2gUgxLuowkS\nOmKn/Oj+jqr8r1FAhnTYBDY3k5lzM9p41l0CQEXQ9j6qSXXYIIllvZv6lX7Wa2Ah\nNR8z+/i5A4XrRZReDnavxyUu5ilHgFsWYhmpHb3jKVXS4KJwi1MGubcmiXkCQQDH\nWrNG5Vhpm0MdXLeLDcNYtO04P2BSpeiC2g81Y7xLUsRyWYEPFvp+vznRCHhhQ0Gu\npht5ZJ4KplNYmBev7QW5AkA2PuQ8n7APgIhi8xBwlZW3jufnSHT8dP6JUCgvvon1\nDvUM22k/ZWRo0mUB4BdGctIqRFiGwB8Hd0WSl7gSb5oF\n-----END RSA PRIVATE KEY-----\n"}`)
	modTag := models.NewModificationTag("epoch", 0)
	desiredLRP := &models.DesiredLRP{
		ProcessGuid:          guid,
		Domain:               "benchmark-bbs",
		RootFs:               "some:rootfs",
		Instances:            1,
		EnvironmentVariables: []*models.EnvironmentVariable{{Name: "FOO", Value: "bar"}},
		Setup:                models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
		Action:               models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
		StartTimeoutMs:       15000,
		Monitor: models.WrapAction(models.EmitProgressFor(
			models.Timeout(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"}))),
				10*time.Second,
			),
			"start-message",
			"success-message",
			"failure-message",
		)),
		DiskMb:    512,
		MemoryMb:  1024,
		CpuWeight: 42,
		Routes: &models.Routes{"my-router": &myRouterJSON,
			"diego-ssh": &myRouterJSON2},
		LogSource:   "some-log-source",
		LogGuid:     "some-log-guid",
		MetricsGuid: "some-metrics-guid",
		Annotation:  "some-annotation",
		EgressRules: []*models.SecurityGroupRule{{
			Protocol:     models.TCPProtocol,
			Destinations: []string{"1.1.1.1/32", "2.2.2.2/32"},
			PortRange:    &models.PortRange{Start: 10, End: 16000},
		}},
		ModificationTag: &modTag,
	}
	err := desiredLRP.Validate()
	if err != nil {
		return nil, err
	}

	return desiredLRP, nil
}
Esempio n. 2
0
func NewValidTaskDefinition() *models.TaskDefinition {
	return &models.TaskDefinition{
		RootFs: "docker:///docker.com/docker",
		EnvironmentVariables: []*models.EnvironmentVariable{
			{
				Name:  "FOO",
				Value: "BAR",
			},
		},
		CachedDependencies: []*models.CachedDependency{
			{Name: "app bits", From: "blobstore.com/bits/app-bits", To: "/usr/local/app", CacheKey: "cache-key", LogSource: "log-source"},
			{Name: "app bits with checksum", From: "blobstore.com/bits/app-bits-checksum", To: "/usr/local/app-checksum", CacheKey: "cache-key", LogSource: "log-source", ChecksumAlgorithm: "md5", ChecksumValue: "checksum-value"},
		},
		Action: models.WrapAction(&models.RunAction{
			User:           "******",
			Path:           "echo",
			Args:           []string{"hello world"},
			ResourceLimits: &models.ResourceLimits{},
		}),
		MemoryMb:    256,
		DiskMb:      1024,
		MaxPids:     1024,
		CpuWeight:   42,
		Privileged:  true,
		LogGuid:     "123",
		LogSource:   "APP",
		MetricsGuid: "456",
		ResultFile:  "some-file.txt",
		EgressRules: []*models.SecurityGroupRule{
			{
				Protocol:     "tcp",
				Destinations: []string{"0.0.0.0/0"},
				PortRange: &models.PortRange{
					Start: 1,
					End:   1024,
				},
				Log: true,
			},
			{
				Protocol:     "udp",
				Destinations: []string{"8.8.0.0/16"},
				Ports:        []uint32{53},
			},
		},
		Annotation: `[{"anything": "you want!"}]... dude`,
		Network: &models.Network{
			Properties: map[string]string{
				"some-key":       "some-value",
				"some-other-key": "some-other-value",
			},
		},
		LegacyDownloadUser:            "******",
		TrustedSystemCertificatesPath: "/etc/somepath",
		VolumeMounts: []*models.VolumeMount{
			{
				Driver:       "my-driver",
				ContainerDir: "/mnt/mypath",
				Mode:         "r",
				Shared: &models.SharedDevice{
					VolumeId:    "my-volume",
					MountConfig: `{"foo":"bar"}`,
				},
			},
		},
		PlacementTags: []string{"red-tag", "blue-tag", "one-tag", "two-tag"},
	}
}
Esempio n. 3
0
func NewValidDesiredLRP(guid string) *models.DesiredLRP {
	myRouterJSON := json.RawMessage(`{"foo":"bar"}`)
	modTag := models.NewModificationTag("epoch", 0)
	desiredLRP := &models.DesiredLRP{
		ProcessGuid:          guid,
		Domain:               "some-domain",
		RootFs:               "some:rootfs",
		Instances:            1,
		EnvironmentVariables: []*models.EnvironmentVariable{{Name: "FOO", Value: "bar"}},
		CachedDependencies: []*models.CachedDependency{
			{Name: "app bits", From: "blobstore.com/bits/app-bits", To: "/usr/local/app", CacheKey: "cache-key", LogSource: "log-source"},
			{Name: "app bits with checksum", From: "blobstore.com/bits/app-bits-checksum", To: "/usr/local/app-checksum", CacheKey: "cache-key", LogSource: "log-source", ChecksumAlgorithm: "md5", ChecksumValue: "checksum-value"},
		},
		Setup:          models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
		Action:         models.WrapAction(&models.RunAction{Path: "ls", User: "******"}),
		StartTimeoutMs: 15000,
		Monitor: models.WrapAction(models.EmitProgressFor(
			models.Timeout(models.Try(models.Parallel(models.Serial(&models.RunAction{Path: "ls", User: "******"}))),
				10*time.Second,
			),
			"start-message",
			"success-message",
			"failure-message",
		)),
		DiskMb:      512,
		MemoryMb:    1024,
		CpuWeight:   42,
		MaxPids:     1024,
		Routes:      &models.Routes{"my-router": &myRouterJSON},
		LogSource:   "some-log-source",
		LogGuid:     "some-log-guid",
		MetricsGuid: "some-metrics-guid",
		Annotation:  "some-annotation",
		Network: &models.Network{
			Properties: map[string]string{
				"some-key":       "some-value",
				"some-other-key": "some-other-value",
			},
		},
		EgressRules: []*models.SecurityGroupRule{{
			Protocol:     models.TCPProtocol,
			Destinations: []string{"1.1.1.1/32", "2.2.2.2/32"},
			PortRange:    &models.PortRange{Start: 10, End: 16000},
		}},
		ModificationTag:               &modTag,
		LegacyDownloadUser:            "******",
		TrustedSystemCertificatesPath: "/etc/somepath",
		PlacementTags:                 []string{"red-tag", "blue-tag"},
		VolumeMounts: []*models.VolumeMount{
			{
				Driver:       "my-driver",
				ContainerDir: "/mnt/mypath",
				Mode:         "r",
				Shared: &models.SharedDevice{
					VolumeId:    "my-volume",
					MountConfig: `{"foo":"bar"}`,
				},
			},
		},
	}
	err := desiredLRP.Validate()
	Expect(err).NotTo(HaveOccurred())

	return desiredLRP
}
Esempio n. 4
0
func NewValidAction() *models.Action {
	return models.WrapAction(&models.RunAction{Path: "ls", User: "******"})
}
Esempio n. 5
0
	BeforeEach(func() {
		fakeRawEventSource = new(eventfakes.FakeRawEventSource)
		eventSource = events.NewEventSource(fakeRawEventSource)
	})

	Describe("Next", func() {
		Describe("Desired LRP events", func() {
			var desiredLRP *models.DesiredLRP

			BeforeEach(func() {
				desiredLRP = &models.DesiredLRP{
					ProcessGuid: "some-guid",
					Domain:      "some-domain",
					RootFs:      "some-rootfs",
					Action: models.WrapAction(&models.RunAction{
						Path: "true",
						User: "******",
					}),
				}
			})

			Context("when receiving a DesiredLRPCreatedEvent", func() {
				var expectedEvent *models.DesiredLRPCreatedEvent

				BeforeEach(func() {
					expectedEvent = models.NewDesiredLRPCreatedEvent(desiredLRP)
					payload, err := proto.Marshal(expectedEvent)
					Expect(err).NotTo(HaveOccurred())
					payload = []byte(base64.StdEncoding.EncodeToString(payload))

					fakeRawEventSource.NextReturns(
						sse.Event{
		It("returns a not implemented error", func() {
			Expect(migration.Down(logger)).To(HaveOccurred())
		})
	})

	Describe("Up", func() {
		var (
			task         *models.Task
			migrationErr error
		)

		Describe("Task Migration", func() {
			BeforeEach(func() {
				task = model_helpers.NewValidTask("task-guid-1")
				task.Action = models.WrapAction(&models.TimeoutAction{Action: model_helpers.NewValidAction(),
					DeprecatedTimeoutNs: 5 * int64(time.Second),
				})
			})

			JustBeforeEach(func() {
				taskData, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, task)
				Expect(err).NotTo(HaveOccurred())
				_, err = storeClient.Set(etcddb.TaskSchemaPath(task), taskData, 0)
				Expect(err).NotTo(HaveOccurred())

				migration.SetStoreClient(storeClient)
				migration.SetCryptor(cryptor)
				migration.SetClock(fakeClock)
				migrationErr = migration.Up(logger)
			})
					err := response.Unmarshal(responseRecorder.Body.Bytes())
					Expect(err).NotTo(HaveOccurred())

					Expect(response.Error).To(BeNil())
					Expect(response.DesiredLrps).To(HaveLen(2))
					Expect(response.DesiredLrps[0]).To(Equal(desiredLRP1.VersionDownTo(format.V1)))
					Expect(response.DesiredLrps[1]).To(Equal(desiredLRP2.VersionDownTo(format.V1)))
				})
			})

			Context("and the desired LRPs have actions with timeout not timeout_ms", func() {
				BeforeEach(func() {
					desiredLRP1.Setup = &models.Action{
						TimeoutAction: &models.TimeoutAction{
							Action: models.WrapAction(&models.UploadAction{
								From: "web_location",
							}),
							TimeoutMs: 10000,
						},
					}
					desiredLRP1.Action = &models.Action{
						TimeoutAction: &models.TimeoutAction{
							Action: models.WrapAction(&models.UploadAction{
								From: "web_location",
							}),
							TimeoutMs: 20000,
						},
					}
					desiredLRP1.Monitor = &models.Action{
						TimeoutAction: &models.TimeoutAction{
							Action: models.WrapAction(&models.UploadAction{
Esempio n. 8
0
		"max_pids": 256
	}`

		task = models.Task{
			TaskDefinition: &models.TaskDefinition{
				RootFs: "docker:///docker.com/docker",
				EnvironmentVariables: []*models.EnvironmentVariable{
					{
						Name:  "ENV_VAR_NAME",
						Value: "an environmment value",
					},
				},
				Action: models.WrapAction(&models.DownloadAction{
					From:              "old_location",
					To:                "new_location",
					CacheKey:          "the-cache-key",
					User:              "******",
					ChecksumAlgorithm: "md5",
					ChecksumValue:     "some value",
				}),
				MemoryMb:    256,
				DiskMb:      1024,
				MaxPids:     256,
				CpuWeight:   42,
				Privileged:  true,
				LogGuid:     "123",
				LogSource:   "APP",
				MetricsGuid: "456",
				ResultFile:  "some-file.txt",

				EgressRules: []*models.SecurityGroupRule{
					{
func (t crashTest) Test() {
	Context(t.Name, func() {
		var (
			crashErr                 error
			shouldRestart            bool
			actualLRPKey             *models.ActualLRPKey
			instanceKey              *models.ActualLRPInstanceKey
			initialTimestamp         int64
			initialModificationIndex uint32

			beforeActualGroup, afterActualGroup *models.ActualLRPGroup
		)

		BeforeEach(func() {
			actualLRP := t.LRP()
			actualLRPKey = &actualLRP.ActualLRPKey
			instanceKey = &actualLRP.ActualLRPInstanceKey

			initialTimestamp = actualLRP.Since
			initialModificationIndex = actualLRP.ModificationTag.Index

			desiredLRP := models.DesiredLRP{
				ProcessGuid: actualLRPKey.ProcessGuid,
				Domain:      actualLRPKey.Domain,
				Instances:   actualLRPKey.Index + 1,
				RootFs:      "foo:bar",
				Action:      models.WrapAction(&models.RunAction{Path: "true", User: "******"}),
			}

			etcdHelper.SetRawDesiredLRP(&desiredLRP)
			etcdHelper.SetRawActualLRP(&actualLRP)
		})

		JustBeforeEach(func() {
			clock.Increment(600)
			beforeActualGroup, afterActualGroup, shouldRestart, crashErr = etcdDB.CrashActualLRP(logger, actualLRPKey, instanceKey, "crashed")
		})

		if t.Result.ReturnedErr == nil {
			It("does not return an error", func() {
				Expect(crashErr).NotTo(HaveOccurred())
			})
		} else {
			It(fmt.Sprintf("returned error should be '%s'", t.Result.ReturnedErr.Error()), func() {
				Expect(crashErr).To(Equal(t.Result.ReturnedErr))
			})
		}

		It(fmt.Sprintf("has crash count %d", t.Result.CrashCount), func() {
			actualLRP, err := etcdHelper.GetInstanceActualLRP(actualLRPKey)
			Expect(err).NotTo(HaveOccurred())
			Expect(actualLRP.CrashCount).To(Equal(t.Result.CrashCount))
		})

		It(fmt.Sprintf("has crash reason %s", t.Result.CrashReason), func() {
			actualLRP, err := etcdHelper.GetInstanceActualLRP(actualLRPKey)
			Expect(err).NotTo(HaveOccurred())
			Expect(actualLRP.CrashReason).To(Equal(t.Result.CrashReason))
		})

		if t.Result.ShouldUpdate {
			It("updates the Since", func() {
				actualLRP, err := etcdHelper.GetInstanceActualLRP(actualLRPKey)
				Expect(err).NotTo(HaveOccurred())
				Expect(actualLRP.Since).To(Equal(clock.Now().UnixNano()))
			})

			It("updates the ModificationIndex", func() {
				actualLRP, err := etcdHelper.GetInstanceActualLRP(actualLRPKey)
				Expect(err).NotTo(HaveOccurred())
				Expect(actualLRP.ModificationTag.Index).To(Equal(initialModificationIndex + 1))
			})

			It("returns the existing and new actual lrp", func() {
				actualLRP := t.LRP()
				actualLRP.Since = 0
				beforeActualGroup.Instance.Since = 0
				Expect(beforeActualGroup).To(Equal(&models.ActualLRPGroup{Instance: &actualLRP}))

				newLRP, err := etcdHelper.GetInstanceActualLRP(actualLRPKey)
				Expect(err).NotTo(HaveOccurred())
				Expect(afterActualGroup.Instance).To(Equal(newLRP))
			})
		} else {
			It("does not update the Since", func() {
				actualLRP, err := etcdHelper.GetInstanceActualLRP(actualLRPKey)
				Expect(err).NotTo(HaveOccurred())
				Expect(actualLRP.Since).To(Equal(initialTimestamp))
			})

			It("does not update the ModificationIndex", func() {
				actualLRP, err := etcdHelper.GetInstanceActualLRP(actualLRPKey)
				Expect(err).NotTo(HaveOccurred())
				Expect(actualLRP.ModificationTag.Index).To(Equal(initialModificationIndex))
			})
		}

		It(fmt.Sprintf("CAS to %s", t.Result.State), func() {
			actualLRP, err := etcdHelper.GetInstanceActualLRP(actualLRPKey)
			Expect(err).NotTo(HaveOccurred())
			Expect(actualLRP.State).To(Equal(t.Result.State))
		})

		if t.Result.Auction {
			It("starts an auction", func() {
				Expect(shouldRestart).To(BeTrue())
			})
		} else {
			It("does not start an auction", func() {
				Expect(shouldRestart).To(BeFalse())
			})
		}

		Context("when crashing a different instance key", func() {
			var beforeActualGroup *models.ActualLRPGroup

			BeforeEach(func() {
				var err error
				beforeActualGroup, err = etcdDB.ActualLRPGroupByProcessGuidAndIndex(logger, actualLRPKey.ProcessGuid, actualLRPKey.Index)
				Expect(err).NotTo(HaveOccurred())
				instanceKey.InstanceGuid = "another-guid"
			})

			It("does not crash", func() {
				Expect(crashErr).To(Equal(models.ErrActualLRPCannotBeCrashed))

				afterActualGroup, err := etcdDB.ActualLRPGroupByProcessGuidAndIndex(logger, actualLRPKey.ProcessGuid, actualLRPKey.Index)
				Expect(err).NotTo(HaveOccurred())
				Expect(afterActualGroup).To(Equal(beforeActualGroup))
			})
		})
	})
}
Esempio n. 10
0
			Eventually(eventChannel).Should(BeClosed())
		})

		Describe("Desired LRPs", func() {
			BeforeEach(func() {
				routeMessage := json.RawMessage([]byte(`[{"port":8080,"hostnames":["original-route"]}]`))
				routes := &models.Routes{"cf-router": &routeMessage}

				desiredLRP = &models.DesiredLRP{
					ProcessGuid: "some-guid",
					Domain:      "some-domain",
					RootFs:      "some:rootfs",
					Routes:      routes,
					Action: models.WrapAction(&models.RunAction{
						User:      "******",
						Dir:       "/tmp",
						Path:      "true",
						LogSource: "logs",
					}),
				}
			})

			It("receives events", func() {
				By("creating a DesiredLRP")
				err := client.DesireLRP(logger, desiredLRP)
				Expect(err).NotTo(HaveOccurred())

				desiredLRP, err := client.DesiredLRPByProcessGuid(logger, desiredLRP.ProcessGuid)
				Expect(err).NotTo(HaveOccurred())

				var event models.Event
				Eventually(eventChannel).Should(Receive(&event))
Esempio n. 11
0
				"router": &rawMessage,
			}
			expectedSchedulingInfo.ModificationTag.Increment()

			schedulingInfo.ApplyUpdate(update)
			Expect(schedulingInfo).To(Equal(expectedSchedulingInfo))
		})
	})

	Describe("Version Down To", func() {
		Context("V1", func() {
			BeforeEach(func() {
				desiredLRP.Setup = models.WrapAction(models.Timeout(
					&models.RunAction{
						Path: "/the/path",
						User: "******",
					},
					10*time.Millisecond,
				))
				desiredLRP.Action = models.WrapAction(models.Timeout(
					&models.RunAction{
						Path: "/the/path",
						User: "******",
					},
					20*time.Millisecond,
				))
				desiredLRP.Monitor = models.WrapAction(models.Timeout(
					&models.RunAction{
						Path: "/the/path",
						User: "******",
					},
Esempio n. 12
0
	itSerializesAndDeserializes := func(actionPayload string, action *models.Action) {
		itSerializes(actionPayload, action)
		itDeserializes(actionPayload, action)
	}

	Describe("WrapAction", func() {
		It("wraps an action into *Action", func() {
			action := &models.DownloadAction{
				Artifact: "mouse",
				From:     "web_location",
				To:       "local_location",
				CacheKey: "elephant",
				User:     "******",
			}
			wrapped := models.WrapAction(action)
			Expect(wrapped).NotTo(BeNil())
			Expect(wrapped.GetValue()).To(Equal(action))
		})

		It("does not wrap nil", func() {
			wrapped := models.WrapAction(nil)
			Expect(wrapped).To(BeNil())
		})
	})

	Describe("Nil Actions", func() {
		It("Action -> JSON for a Nil action", func() {
			var action *models.Action = nil
			By("marshalling to JSON", func() {
				json, err := json.Marshal(action)