// CreateRecordMatchRunHandler creates a HandlerFunc that creates a new
// RecordMatchRun and constructs and sends a Record Match request message.
961286
func CreateRecordMatchRunHandler(provider func() *mgo.Database) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		recMatchRun := &ptm_models.RecordMatchRun{}
		if err := ctx.Bind(recMatchRun); err != nil {
			ctx.AbortWithError(http.StatusInternalServerError, err)
			return
		}

		if !isValidRecordMatchRun(recMatchRun) {
			// Bad Request: Record Match Run contains invalid content
			ctx.String(http.StatusBadRequest, "Invalid RecordMatchRun content")
			ctx.Abort()
			return
		}

		// retrieve and validate the record match context
		recMatchContextID := recMatchRun.RecordMatchContextID
		logger.Log.WithFields(
			logrus.Fields{"method": "CreateRecordMatchRun",
				"recMatchContextID": recMatchContextID}).Debug("check recmatch config id")
		if !recMatchContextID.Valid() {
			// Bad Request: Record Match Context is optional but must be valid, if provided
			ctx.String(http.StatusBadRequest, "Invalid RecordMatchContextID")
			ctx.Abort()
			return
		}

		// Retrieve the info about the record matcher
		obj, err := ptm_models.LoadResource(provider(), "RecordMatchSystemInterface",
			recMatchRun.RecordMatchSystemInterfaceID)
		if err != nil {
			ctx.String(http.StatusBadRequest, "Unable to find Record Match System Interface")
			ctx.Abort()
			return
		}
		recMatchSysIface := obj.(*ptm_models.RecordMatchSystemInterface)
		if !isValidRecordMatchSysIface(recMatchSysIface) {
			ctx.String(http.StatusBadRequest, "Invalid Record Match System Interface")
			ctx.Abort()
			return
		}

		// construct a record match request
		reqMatchRequest, err := newRecordMatchRequest(recMatchSysIface.ResponseEndpoint, recMatchRun, provider())
		if err != nil {
			logger.Log.WithFields(
				logrus.Fields{"method": "CreateRecordMatchRun",
					"err": err}).Warn("Unable to create Record Match Request")
			ctx.AbortWithError(http.StatusBadRequest, err)
			return
		}
		// attach the request message to the run object
		recMatchRun.Request = *reqMatchRequest

		// Construct body of the http request for the record match request
		reqBody, _ := reqMatchRequest.Message.MarshalJSON()

		svrEndpoint := prepEndpoint(recMatchSysIface.ServerEndpoint, reqMatchRequest.Message.Id)

		logger.Log.WithFields(
			logrus.Fields{"method": "CreateRecordMatchRun",
				"server endpoint": svrEndpoint,
				"reqBody":         string(reqBody[:]),
				"message":         reqMatchRequest.Message}).Info("About to submit request")

		reqMatchRequest.SubmittedOn = time.Now()

		// Send the record match request to a FHIR server acting as msg broker.
		resp, err := ptm_http.Put(svrEndpoint, "application/json+fhir",
			bytes.NewReader(reqBody))
		if err != nil {
			// HACK In this configuration, the test harness only supports itself as the FHIR message broker
			if resp.StatusCode == 302 {
				logger.Log.Debug("CreateRecordMatchRun: redirect detected - Infer server is in Heart mode")
				_, err = ptm_models.PersistFhirResource(provider(), "Bundle", reqMatchRequest.Message)
				if err != nil {
					ctx.AbortWithError(http.StatusInternalServerError, err)
					return
				}
			} else {
				logger.Log.WithFields(
					logrus.Fields{"method": "CreateRecordMatchRun",
						"err": err}).Warn("Sending Record Match Request")
				ctx.AbortWithError(http.StatusInternalServerError, err)
				return
			}
		}
		logger.Log.WithFields(
			logrus.Fields{"method": "CreateRecordMatchRun",
				"status": resp.StatusCode}).Info("Put Response Status")

		// Store status, Sent, with the run object
		recMatchRun.Status = make([]ptm_models.RecordMatchRunStatusComponent, 1)
		recMatchRun.Status[0].CreatedOn = time.Now()
		// if a success code was received
		if resp.StatusCode >= 200 && resp.StatusCode < 300 {
			recMatchRun.Status[0].Message = "Request Sent [" + resp.Status + "]"
		} else if resp.StatusCode == 302 {
			recMatchRun.Status[0].Message = "Redirect from Msg Broker Not Supported; Request persisted in local database"
		} else {
			recMatchRun.Status[0].Message = "Error Sending Request to Record Matcher [" + resp.Status + "]"
		}

		// Persist the record match run
		resource, err := ptm_models.PersistResource(provider(), "RecordMatchRun", recMatchRun)
		if err != nil {
			ctx.AbortWithError(http.StatusInternalServerError, err)
			return
		}

		ctx.JSON(http.StatusCreated, resource)
	}
}
1140979
func (mr *MockEventCollectorMockRecorder) CollectTraceEvent(records interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CollectTraceEvent", reflect.TypeOf((*MockEventCollector)(nil).CollectTraceEvent), records)
}
450011
func (client *Client) CreateRunstatusService(ctx context.Context, service RunstatusService) (*RunstatusService, error) {
	if service.PageURL == "" {
		return nil, fmt.Errorf("empty Page URL for %#v", service)
	}

	page, err := client.GetRunstatusPage(ctx, RunstatusPage{URL: service.PageURL})
	if err != nil {
		return nil, err
	}

	resp, err := client.runstatusRequest(ctx, page.ServicesURL, service, "POST")
	if err != nil {
		return nil, err
	}

	s := &RunstatusService{}
	if err := json.Unmarshal(resp, s); err != nil {
		return nil, err
	}

	return s, nil
}
956169
func RecordLongRunning(req *http.Request, requestInfo *request.RequestInfo, component string, fn func()) {
	if requestInfo == nil {
		requestInfo = &request.RequestInfo{Verb: req.Method, Path: req.URL.Path}
	}
	var g prometheus.Gauge
	scope := CleanScope(requestInfo)
	reportedVerb := cleanVerb(strings.ToUpper(requestInfo.Verb), req)
	if requestInfo.IsResourceRequest {
		g = longRunningRequestGauge.WithLabelValues(reportedVerb, requestInfo.APIGroup, requestInfo.APIVersion, requestInfo.Resource, requestInfo.Subresource, scope, component)
	} else {
		g = longRunningRequestGauge.WithLabelValues(reportedVerb, "", "", "", requestInfo.Path, scope, component)
	}
	g.Inc()
	defer g.Dec()
	fn()
}
839208
func createPollingTracker(resp *http.Response) (pollingTracker, error) {
	var pt pollingTracker
	switch strings.ToUpper(resp.Request.Method) {
	case http.MethodDelete:
		pt = &pollingTrackerDelete{pollingTrackerBase: pollingTrackerBase{resp: resp}}
	case http.MethodPatch:
		pt = &pollingTrackerPatch{pollingTrackerBase: pollingTrackerBase{resp: resp}}
	case http.MethodPost:
		pt = &pollingTrackerPost{pollingTrackerBase: pollingTrackerBase{resp: resp}}
	case http.MethodPut:
		pt = &pollingTrackerPut{pollingTrackerBase: pollingTrackerBase{resp: resp}}
	default:
		return nil, autorest.NewError("azure", "createPollingTracker", "unsupported HTTP method %s", resp.Request.Method)
	}
	if err := pt.initializeState(); err != nil {
		return pt, err
	}
	// this initializes the polling header values, we do this during creation in case the
	// initial response send us invalid values; this way the API call will return a non-nil
	// error (not doing this means the error shows up in Future.Done)
	return pt, pt.updatePollingMethod()
}
38086
func (rg *RecordGenerator) listenerRecord(listener string, ns string) {
	if listener == "0.0.0.0" {
		rg.setFromLocal(listener, ns)
	} else if listener == "127.0.0.1" {
		rg.insertRR(ns, "127.0.0.1", A)
	} else {
		rg.insertRR(ns, listener, rrsKindForIPStr(listener))
	}
}
519336
func (client *AuroraDNSClient) CreateRecord(zoneID string, data records.CreateRecordRequest) (*records.CreateRecordResponse, error) {
	logrus.Debugf("CreateRecord(%s, %+v)", zoneID, data)
	body, err := json.Marshal(data)
	if err != nil {
		logrus.Errorf("Failed to marshall request body: %s", err)

		return nil, err
	}

	relativeURL := fmt.Sprintf("zones/%s/records", zoneID)

	response, err := client.requestor.Request(relativeURL, "POST", body)
	if err != nil {
		logrus.Errorf("Failed to create record: %s", err)

		return nil, err
	}

	var respData *records.CreateRecordResponse
	err = json.Unmarshal(response, &respData)
	if err != nil {
		logrus.Errorf("Failed to unmarshall response: %s", err)

		return nil, err
	}

	return respData, nil
}
851423
func (c *Tracing) RecordClockSyncMarkerWithParams(v *TracingRecordClockSyncMarkerParams) (*gcdmessage.ChromeResponse, error) {
	return gcdmessage.SendDefaultRequest(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Tracing.recordClockSyncMarker", Params: v})
}
667972
func (r *recorder) runServer(h http.Handler) {
	// read from the recorder connection the request sent by the recorder.Dial,
	// and use the handler to serve this request.
	req, err := http.ReadRequest(bufio.NewReader(r.server))
	if err != nil {
		return
	}
	h.ServeHTTP(r, req)
}
470901
func (s *UpdateRecordsInput) SetRecordPatches(v []*RecordPatch) *UpdateRecordsInput {
	s.RecordPatches = v
	return s
}
1068886
func (ar *avroRecord) createObjectFromRecord(record interface{}) error {
	jsonObj, err := json.Marshal(record)
	if err != nil {
		fwColLog.Debugf("Bad record:\n%s", record)
		return err
	}

	fwColLog.Debugf("JSON Record:\n%s", string(jsonObj))
	return json.Unmarshal(jsonObj, &ar)
}
969335
func MatchHandler(key string, value interface{}, h LogHandler) LogHandler {
	return MatchFilterHandler(key, value, h)
}
632654
func (h *BasicHost) SetStreamHandlerMatch(pid protocol.ID, m func(string) bool, handler inet.StreamHandler) {
	h.Mux().AddHandlerWithFunc(string(pid), m, func(p string, rwc io.ReadWriteCloser) error {
		is := rwc.(inet.Stream)
		is.SetProtocol(protocol.ID(p))
		handler(is)
		return nil
	})
}
57501
func (mr *MockCoreStorageMockRecorder) CreateRefreshTokenSession(arg0, arg1, arg2 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateRefreshTokenSession", reflect.TypeOf((*MockCoreStorage)(nil).CreateRefreshTokenSession), arg0, arg1, arg2)
}
783506
func CallerFileHandler(h Handler) Handler {
	return FuncHandler(func(r *Record) error {
		r.Ctx = append(r.Ctx, "caller", fmt.Sprint(r.Call))
		return h.Log(r)
	})
}
902274
func (mr *MockCustomResourceDefinitionInterfaceMockRecorder) Create(arg0 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockCustomResourceDefinitionInterface)(nil).Create), arg0)
}
618694
func NewMockStringsWatcher(ctrl *gomock.Controller) *MockStringsWatcher {
	mock := &MockStringsWatcher{ctrl: ctrl}
	mock.recorder = &MockStringsWatcherMockRecorder{mock}
	return mock
}