<commit_before>package harvester

import (
	"github.com/cloudfoundry-incubator/executor"
	"github.com/cloudfoundry-incubator/rep"
	"github.com/cloudfoundry-incubator/runtime-schema/bbs"
	"github.com/cloudfoundry-incubator/runtime-schema/bbs/bbserrors"
	"github.com/pivotal-golang/lager"
)

type lrpProcessor struct {
	cellID         string
	logger         lager.Logger
	bbs            bbs.RepBBS
	executorClient executor.Client
}

func NewLRPProcessor(
	cellID string,
	logger lager.Logger,
	bbs bbs.RepBBS,
	executorClient executor.Client,
) Processor {
	return &lrpProcessor{
		cellID:         cellID,
		logger:         logger,
		bbs:            bbs,
		executorClient: executorClient,
	}
}

func (p *lrpProcessor) Process(container executor.Container) {
	logger := p.logger.Session("process-lrp", lager.Data{
		"container-guid":  container.Guid,
		"container-state": container.State,
	})

	if container.State == executor.StateReserved {
		logger.Debug("ignoring-reserved-container")
		return
	}

	lrpKey, err := rep.ActualLRPKeyFromContainer(container)
	if err != nil {
		logger.Error("failed-to-generate-lrp-key-from-container", err)
		return
	}

	lrpContainerKey, err := rep.ActualLRPContainerKeyFromContainer(container, p.cellID)
	if err != nil {
		logger.Error("failed-to-generate-container-key-from-container", err)
		return
	}

	lrpNetInfo, err := rep.ActualLRPNetInfoFromContainer(container)
	if err != nil {
		logger.Error("failed-to-generate-net-info-from-container", err)
		return
	}

	switch container.State {
	case executor.StateInitializing, executor.StateCreated:
		err = p.bbs.ClaimActualLRP(lrpKey, lrpContainerKey, logger)
		if err == bbserrors.ErrActualLRPCannotBeClaimed {
			logger.Debug("failed-to-claim-actual-lrp")
			p.deleteContainer(lrpContainerKey.InstanceGuid, logger)
			return
		}
		if err != nil {
			logger.Error("failed-to-claim-actual-lrp", err)
			return
		}
		logger.Debug("claimed-actual-lrp")

	case executor.StateRunning:
		err := p.bbs.StartActualLRP(lrpKey, lrpContainerKey, lrpNetInfo, logger)
		if err == bbserrors.ErrActualLRPCannotBeStarted {<commit_msg>only get net info if actuallrp is running<commit_after>package harvester

import (
	"github.com/cloudfoundry-incubator/executor"
	"github.com/cloudfoundry-incubator/rep"
	"github.com/cloudfoundry-incubator/runtime-schema/bbs"
	"github.com/cloudfoundry-incubator/runtime-schema/bbs/bbserrors"
	"github.com/pivotal-golang/lager"
)

type lrpProcessor struct {
	cellID         string
	logger         lager.Logger
	bbs            bbs.RepBBS
	executorClient executor.Client
}

func NewLRPProcessor(
	cellID string,
	logger lager.Logger,
	bbs bbs.RepBBS,
	executorClient executor.Client,
) Processor {
	return &lrpProcessor{
		cellID:         cellID,
		logger:         logger,
		bbs:            bbs,
		executorClient: executorClient,
	}
}

func (p *lrpProcessor) Process(container executor.Container) {
	logger := p.logger.Session("process-lrp", lager.Data{
		"container-guid":  container.Guid,
		"container-state": container.State,
	})

	if container.State == executor.StateReserved {
		logger.Debug("ignoring-reserved-container")
		return
	}

	lrpKey, err := rep.ActualLRPKeyFromContainer(container)
	if err != nil {
		logger.Error("failed-to-generate-lrp-key-from-container", err)
		return
	}

	lrpContainerKey, err := rep.ActualLRPContainerKeyFromContainer(container, p.cellID)
	if err != nil {
		logger.Error("failed-to-generate-container-key-from-container", err)
		return
	}

	switch container.State {
	case executor.StateInitializing, executor.StateCreated:
		err = p.bbs.ClaimActualLRP(lrpKey, lrpContainerKey, logger)
		if err == bbserrors.ErrActualLRPCannotBeClaimed {
			logger.Debug("failed-to-claim-actual-lrp")
			p.deleteContainer(lrpContainerKey.InstanceGuid, logger)
			return
		}
		if err != nil {
			logger.Error("failed-to-claim-actual-lrp", err)
			return
		}
		logger.Debug("claimed-actual-lrp")

	case executor.StateRunning:
		lrpNetInfo, err := rep.ActualLRPNetInfoFromContainer(container)
		if err != nil {
			logger.Error("failed-to-generate-net-info-from-container", err)
			return
		}

		err = p.bbs.StartActualLRP(lrpKey, lrpContainerKey, lrpNetInfo, logger)
		if err == bbserrors.ErrActualLRPCannotBeStarted {
{'fraction_non_alphanumeric': 0.11691072272083136, 'fraction_numerical': 0.0, 'mean_word_length': 4.158343483556639, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1329967', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1491, 'n_words': 243}