Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@ vector<Selectable *> Orch::getSelectables()
return selectables;
}

void Consumer::execute()
void Consumer::addToSync(std::deque<KeyOpFieldsValuesTuple> &entries)
{
SWSS_LOG_ENTER();

std::deque<KeyOpFieldsValuesTuple> entries;
getConsumerTable()->pops(entries);

/* Nothing popped */
if (entries.empty())
{
Expand Down Expand Up @@ -123,6 +120,16 @@ void Consumer::execute()
m_toSync[key] = KeyOpFieldsValuesTuple(key, op, existing_values);
}
}
}

void Consumer::execute()
{
SWSS_LOG_ENTER();

std::deque<KeyOpFieldsValuesTuple> entries;
getConsumerTable()->pops(entries);

addToSync(entries);

drain();
}
Expand All @@ -133,6 +140,51 @@ void Consumer::drain()
m_orch->doTask(*this);
}

/* Fetch existing table data for consumer of the specified table */
void Orch::addExistingData(DBConnector *db, string tableName)
{
Consumer* consumer;
auto it = m_consumerMap.begin();

while (it != m_consumerMap.end())
{
// Executor (not Consumer) may be in m_consumerMap, don't cast
if (tableName == (it->second.get())->getName())
{
break;
}
it++;
}

if (it == m_consumerMap.end())
{
return;
}
// Now we are sure that it is a Consumer
consumer = (Consumer*)(it->second.get());

std::deque<KeyOpFieldsValuesTuple> entries;
Table table = Table(db, tableName);
vector<string> keys;

table.getKeys(keys);
for (const auto &key: keys)
{
KeyOpFieldsValuesTuple kco;

kfvKey(kco) = key;
kfvOp(kco) = SET_COMMAND;

if (!table.get(key, kfvFieldsValues(kco)))
{
continue;
}
entries.push_back(kco);
}

consumer->addToSync(entries);
}

/*
- Validates reference has proper format which is [table_name:object_name]
- validates table_name exists
Expand Down
20 changes: 20 additions & 0 deletions orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,21 @@ class Executor : public Selectable
virtual void execute() { }
virtual void drain() { }

virtual string getName() const
{
return m_name;
}
virtual void setName(string name)
{
m_name = name;
}
protected:
Selectable *m_selectable;
Orch *m_orch;

// Name for Executor
string m_name;

// Get the underlying selectable
Selectable *getSelectable() const { return m_selectable; }
};
Expand All @@ -116,8 +127,14 @@ class Consumer : public Executor {
return getConsumerTable()->getTableName();
}

string getName() const
{
return getConsumerTable()->getTableName();
}

void execute();
void drain();
void addToSync(std::deque<KeyOpFieldsValuesTuple> &entries);

/* Store the latest 'golden' status */
// TODO: hide?
Expand Down Expand Up @@ -149,6 +166,9 @@ class Orch

vector<Selectable*> getSelectables();

// add the existing data to the consumer todo task list.
void addExistingData(DBConnector *db, string tableName);

/* Iterate all consumers in m_consumerMap and run doTask(Consumer) */
void doTask();

Expand Down