Skip to content

Commit

Permalink
Attempting a more minimal Ignition to Gazebo server rename effort (#263)
Browse files Browse the repository at this point in the history
Signed-off-by: Nate Koenig <nate@openrobotics.org>

Signed-off-by: Nate Koenig <nate@openrobotics.org>
Co-authored-by: Nate Koenig <nate@openrobotics.org>
  • Loading branch information
nkoenig and Nate Koenig authored Aug 15, 2022
1 parent dd94c11 commit 716c966
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
5 changes: 5 additions & 0 deletions include/ignition/fuel_tools/ModelIdentifier.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ namespace ignition
/// \return True if the ModelIdentifier names are equal.
public: bool operator==(const ModelIdentifier &_rhs) const;

/// \brief Inequality operator.
/// \param[in] _rhs ModelIdentifier to compare.
/// \return True if the ModelIdentifier names are not equal.
public: bool operator!=(const ModelIdentifier &_rhs) const;

/// \brief Returns just the last part of the model name.
/// \return Model name.
public: std::string Name() const;
Expand Down
6 changes: 6 additions & 0 deletions src/ClientConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class ignition::fuel_tools::ClientConfigPrivate
homePath, ".ignition", "fuel");

this->servers.push_back(ServerConfig());

// Add in fuel.gazebosim.org as another default server config.
ServerConfig gzServerConfig;
gzServerConfig.SetUrl(common::URI("https://fuel.gazebosim.org"));
gzServerConfig.SetVersion("1.0");
this->servers.push_back(gzServerConfig);
}

/// \brief Clear values.
Expand Down
14 changes: 9 additions & 5 deletions src/ClientConfig_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ std::string cachePath()
TEST(ClientConfig, InitiallyDefaultServers)
{
ClientConfig config;
EXPECT_EQ(1u, config.Servers().size());
EXPECT_EQ(2u, config.Servers().size());
}

/////////////////////////////////////////////////
Expand All @@ -88,7 +88,7 @@ TEST(ClientConfig, ServersCanBeAdded)
srv.SetUrl(common::URI("http://asdf"));
config.AddServer(srv);

ASSERT_EQ(2u, config.Servers().size());
ASSERT_EQ(3u, config.Servers().size());
EXPECT_EQ(std::string("http://asdf"), config.Servers().back().Url().Str());
}

Expand All @@ -97,9 +97,11 @@ TEST(ClientConfig, ServersCanBeAdded)
TEST(ClientConfig, CustomDefaultConfiguration)
{
ClientConfig config;
ASSERT_EQ(1u, config.Servers().size());
ASSERT_EQ(2u, config.Servers().size());
EXPECT_EQ("https://fuel.ignitionrobotics.org",
config.Servers().front().Url().Str());
EXPECT_EQ("https://fuel.gazebosim.org",
config.Servers()[1].Url().Str());

std::string defaultCacheLocation = common::joinPaths(
homePath(), ".ignition", "fuel");
Expand Down Expand Up @@ -134,11 +136,13 @@ TEST(ClientConfig, CustomConfiguration)

EXPECT_TRUE(config.LoadConfig(testPath));

ASSERT_EQ(3u, config.Servers().size());
ASSERT_EQ(4u, config.Servers().size());
EXPECT_EQ("https://fuel.ignitionrobotics.org",
config.Servers().front().Url().Str());
EXPECT_EQ("https://api.ignitionfuel.org",
EXPECT_EQ("https://fuel.gazebosim.org",
config.Servers()[1].Url().Str());
EXPECT_EQ("https://api.ignitionfuel.org",
config.Servers()[2].Url().Str());
EXPECT_EQ("https://myserver",
config.Servers().back().Url().Str());

Expand Down
12 changes: 8 additions & 4 deletions src/FuelClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,16 @@ Result FuelClient::DownloadModel(const ModelIdentifier &_id,
if(!res)
return res;

for (auto dep : dependencies)
for (ModelIdentifier dep : dependencies)
{
auto dep_res = this->DownloadModel(dep, _headers);
// Download dependency if not in the local cache
if (!this->dataPtr->cache->MatchingModel(dep))
{
auto dep_res = this->DownloadModel(dep, _headers);

if(!dep_res)
return dep_res;
if(!dep_res)
return dep_res;
}
}

return res;
Expand Down
8 changes: 5 additions & 3 deletions src/FuelClient_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,14 @@ TEST_F(FuelClientTest, DownloadModel)
EXPECT_EQ(ResultType::FETCH_ALREADY_EXISTS, res5.Type());
}

// Download model with a dependency specified within its `model.config`
// Download model with a dependency specified within its `model.config`.
// The dependency points to fuel.gazebosim.org.
{
common::URI url{
"https://fuel.ignitionrobotics.org/1.0/JShep1/models/hatchback_red_2"};
"https://fuel.ignitionrobotics.org/1.0/openrobotics/models/hatchback red"
};
common::URI depUrl{
"https://fuel.ignitionrobotics.org/1.0/JShep1/models/hatchback_2"};
"https://fuel.gazebosim.org/1.0/openrobotics/models/hatchback"};

// Check it is not cached
std::string cachedPath;
Expand Down
3 changes: 0 additions & 3 deletions src/LocalCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ std::vector<Model> LocalCachePrivate::ModelsInServer(
{
std::vector<Model> models;
if (!common::isDirectory(_path))
{
ignwarn << "Server directory does not exist [" << _path << "]\n";
return models;
}

common::DirIter end;
common::DirIter ownIter(_path);
Expand Down
6 changes: 6 additions & 0 deletions src/ModelIdentifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ bool ModelIdentifier::operator==(const ModelIdentifier &_rhs) const
return this->UniqueName() == _rhs.UniqueName();
}

//////////////////////////////////////////////////
bool ModelIdentifier::operator!=(const ModelIdentifier &_rhs) const
{
return !(*this == _rhs);
}

//////////////////////////////////////////////////
ModelIdentifier::~ModelIdentifier()
{
Expand Down
2 changes: 2 additions & 0 deletions src/ModelIdentifier_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ TEST(ModelIdentifier, CopyConstructorDeepCopy)
EXPECT_EQ(2048u, id2.FileSize());
EXPECT_EQ(d1, id2.ModifyDate());
EXPECT_EQ(d2, id2.UploadDate());
EXPECT_EQ(id, id2);

id2.SetName("hello2");
EXPECT_EQ(std::string("hello"), id.Name());
EXPECT_EQ(std::string("hello2"), id2.Name());
EXPECT_NE(id, id2);
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit 716c966

Please sign in to comment.