Exemple #1
0
func (task *Task) UnmarshalJSON(data []byte) error {
	var oldtask oldmodels.Task
	err := json.Unmarshal(data, &oldtask)
	if err != nil {
		return err
	}

	b, err := oldmodels.MarshalAction(oldtask.Action)
	if err != nil {
		return err
	}
	var newAction Action
	err = json.Unmarshal(b, &newAction)

	b, err = json.Marshal(oldtask.EgressRules)
	if err != nil {
		return err
	}

	var newEgressRules []*SecurityGroupRule
	err = json.Unmarshal(b, &newEgressRules)
	if err != nil {
		return err
	}

	task.TaskDefinition = &TaskDefinition{}

	task.TaskGuid = oldtask.TaskGuid
	task.Domain = oldtask.Domain
	task.RootFs = oldtask.RootFS
	task.EnvironmentVariables = EnvironmentVariablesFromModel(oldtask.EnvironmentVariables)
	task.CellId = oldtask.CellID
	task.Action = &newAction
	task.ResultFile = oldtask.ResultFile
	task.Result = oldtask.Result
	task.Failed = oldtask.Failed
	task.FailureReason = oldtask.FailureReason
	task.MemoryMb = int32(oldtask.MemoryMB)
	task.DiskMb = int32(oldtask.DiskMB)
	task.CpuWeight = uint32(oldtask.CPUWeight)
	task.Privileged = oldtask.Privileged
	task.LogGuid = oldtask.LogGuid
	task.LogSource = oldtask.LogSource
	task.MetricsGuid = oldtask.MetricsGuid
	task.CreatedAt = oldtask.CreatedAt
	task.UpdatedAt = oldtask.UpdatedAt
	task.FirstCompletedAt = oldtask.FirstCompletedAt
	task.State = Task_State(oldtask.State)
	task.Annotation = oldtask.Annotation
	task.EgressRules = newEgressRules
	if oldtask.CompletionCallbackURL != nil {
		task.CompletionCallbackUrl = oldtask.CompletionCallbackURL.String()
	}

	return nil
}
Exemple #2
0
func (request DesiredLRPCreateRequest) MarshalJSON() ([]byte, error) {
	var setupRaw, actionRaw, monitorRaw *json.RawMessage

	if request.Action != nil {
		raw, err := oldmodels.MarshalAction(request.Action)
		if err != nil {
			return nil, err
		}
		rm := json.RawMessage(raw)
		actionRaw = &rm
	}

	if request.Setup != nil {
		raw, err := oldmodels.MarshalAction(request.Setup)
		if err != nil {
			return nil, err
		}
		rm := json.RawMessage(raw)
		setupRaw = &rm
	}

	if request.Monitor != nil {
		raw, err := oldmodels.MarshalAction(request.Monitor)
		if err != nil {
			return nil, err
		}
		rm := json.RawMessage(raw)
		monitorRaw = &rm
	}

	innerRequest := InnerDesiredLRPCreateRequest(request)
	mRequest := &mDesiredLRPCreateRequest{
		SetupRaw:                     setupRaw,
		ActionRaw:                    actionRaw,
		MonitorRaw:                   monitorRaw,
		InnerDesiredLRPCreateRequest: &innerRequest,
	}

	return json.Marshal(mRequest)
}
Exemple #3
0
func (response DesiredLRPResponse) MarshalJSON() ([]byte, error) {
	var setupRaw, actionRaw, monitorRaw *json.RawMessage

	if response.Action != nil {
		raw, err := models.MarshalAction(response.Action)
		if err != nil {
			return nil, err
		}
		rm := json.RawMessage(raw)
		actionRaw = &rm
	}

	if response.Setup != nil {
		raw, err := models.MarshalAction(response.Setup)
		if err != nil {
			return nil, err
		}
		rm := json.RawMessage(raw)
		setupRaw = &rm
	}
	if response.Monitor != nil {
		raw, err := models.MarshalAction(response.Monitor)
		if err != nil {
			return nil, err
		}
		rm := json.RawMessage(raw)
		monitorRaw = &rm
	}

	innerResponse := InnerDesiredLRPResponse(response)
	mResponse := &mDesiredLRPResponse{
		SetupRaw:                setupRaw,
		ActionRaw:               actionRaw,
		MonitorRaw:              monitorRaw,
		InnerDesiredLRPResponse: &innerResponse,
	}

	return json.Marshal(mResponse)
}
Exemple #4
0
func (request TaskCreateRequest) MarshalJSON() ([]byte, error) {
	actionRaw, err := oldmodels.MarshalAction(request.Action)
	if err != nil {
		return nil, err
	}

	innerRequest := InnerTaskCreateRequest(request)
	mRequest := &mTaskCreateRequest{
		ActionRaw:              actionRaw,
		InnerTaskCreateRequest: &innerRequest,
	}

	return json.Marshal(mRequest)
}
Exemple #5
0
func (response TaskResponse) MarshalJSON() ([]byte, error) {
	actionRaw, err := oldmodels.MarshalAction(response.Action)
	if err != nil {
		return nil, err
	}

	innerResponse := InnerTaskResponse(response)
	mResponse := &mTaskResponse{
		ActionRaw:         actionRaw,
		InnerTaskResponse: &innerResponse,
	}

	return json.Marshal(mResponse)
}
var _ = Describe("Actions", func() {
	itSerializes := func(actionPayload string, action models.Action) {
		It("Action -> JSON for "+string(action.ActionType()), func() {
			By("marshalling to JSON", func() {
				marshalledAction := action

				json, err := json.Marshal(&marshalledAction)
				Expect(err).NotTo(HaveOccurred())
				Expect(json).To(MatchJSON(actionPayload))
			})

			wrappedJSON := fmt.Sprintf(`{"%s":%s}`, action.ActionType(), actionPayload)
			By("wrapping", func() {
				marshalledAction := action

				json, err := models.MarshalAction(marshalledAction)
				Expect(err).NotTo(HaveOccurred())
				Expect(json).To(MatchJSON(wrappedJSON))
			})
		})
	}

	itDeserializes := func(actionPayload string, action models.Action) {
		It("JSON -> Action for "+string(action.ActionType()), func() {
			wrappedJSON := fmt.Sprintf(`{"%s":%s}`, action.ActionType(), actionPayload)

			By("unwrapping", func() {
				var unmarshalledAction models.Action
				unmarshalledAction, err := models.UnmarshalAction([]byte(wrappedJSON))
				Expect(err).NotTo(HaveOccurred())
				Expect(unmarshalledAction).To(Equal(action))