Skip to content

Commit bb0a08b

Browse files
authored
Merge pull request #31756 from loganharbour/webserver_remote
Rework runner strategy in `MooseControl`, add testing
2 parents fceb480 + efeecdf commit bb0a08b

File tree

79 files changed

+7937
-1694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+7937
-1694
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ python/peacock/tests/postprocessor_tab/TestPostprocessorPluginManager_test_scrip
249249
peacock_tmp_diff.exo
250250
*.e.diff
251251

252+
# Python
253+
.coverage
254+
252255
# configure
253256
_configs.sed
254257
autom4te.cache

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/conf_vars.mk.in @lindsayad
1515
/configure @lindsayad
1616
/configure.ac @lindsayad
17+
/pyproject.toml @loganharbour @zachmprince
1718

1819
/.github @permcody
1920

framework/contrib/tinyhttp/src/tinyhttp/http.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ void HttpServer::startListening(const std::variant<uint16_t, std::string> listen
355355
const auto filename = std::get<std::string>(listen_on);
356356
struct sockaddr_un remote;
357357
remote.sun_family = AF_LOCAL;
358-
strncpy (remote.sun_path, filename.c_str(), sizeof (remote.sun_path));
358+
strcpy(remote.sun_path, filename.c_str());
359359
remote.sun_path[sizeof (remote.sun_path) - 1] = '\0';
360360
const auto remote_size = offsetof (struct sockaddr_un, sun_path) + strlen (remote.sun_path);
361361
const auto retval = bind(mSocket, reinterpret_cast<struct sockaddr*>(&remote), remote_size);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# StartWebServerControlAction
2+
3+
Starts the webserver for all [WebServerControl.md] objects.

framework/doc/content/source/controls/WebServerControl.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The `WebServerControl` object is designed to allow an external process to contro
44

55
The server can either listen on a port via the [!param](/Controls/WebServerControl/port) parameter, or on a unix file socket via the [!param](/Controls/WebServerControl/file_socket) parameter. One of these two parameters must be provided.
66

7-
It can then be managed via the [MooseControl](MooseControl/index.md optional=true) python utility.
7+
It can then be managed via the [MooseControl](moosecontrol/index.md optional=true) python utility.
88

99
## API
1010

@@ -49,7 +49,7 @@ where `<EXEC_ON_FLAG>` is the current execution flag. If the control is not curr
4949
}
5050
```
5151

52-
This endpoint can be accessed via the [MooseControl](MooseControl/index.md optional=true) python utility via the following methods:
52+
This endpoint can be accessed via the [MooseControl](moosecontrol/index.md optional=true) python utility via the following methods:
5353

5454
- `wait()`: Waits for the control to be waiting
5555
- `getWaitingFlag()`: Gets the current flag that the control is waiting on, if any
@@ -124,7 +124,7 @@ where `<NAME>` is the string path to the controllable parameter, `<TYPE>` is the
124124

125125
On success, the response will be empty with a status code of 201.
126126

127-
This endpoint can be accessed via the [MooseControl](MooseControl/index.md optional=true) python utility via the following methods:
127+
This endpoint can be accessed via the [MooseControl](moosecontrol/index.md optional=true) python utility via the following methods:
128128

129129
- `setControllableBool()`: Sets a controllable `bool` parameter
130130
- `setControllableReal()`: Sets a controllable `Real` parameter
@@ -137,13 +137,13 @@ This endpoint can be accessed via the [MooseControl](MooseControl/index.md optio
137137

138138
Tells a waiting control to continue with the execution. The control must be waiting in order to access this endpoint.
139139

140-
Interact with this endpoint by a `GET` request to `/continue`. On success, the response will be empty with a status code of 200. This endpoint can be accessed via the [MooseControl](MooseControl/index.md optional=true) python utility via `setContinue()`.
140+
Interact with this endpoint by a `GET` request to `/continue`. On success, the response will be empty with a status code of 200. This endpoint can be accessed via the [MooseControl](moosecontrol/index.md optional=true) python utility via `setContinue()`.
141141

142142
### `terminate`
143143

144144
Tells a waiting control to terminate the simulation at the end of the current timestep. Any other execution points in the control during the timestep will be skipped. The control must be waiting in order to access this endpoint.
145145

146-
Interact with this endpoint by a `GET` request to `/terminate`. On success, the response will be empty with a status code of 200. This endpoint can be accessed via the [MooseControl](MooseControl/index.md optional=true) python utility via `setTerminate()`.
146+
Interact with this endpoint by a `GET` request to `/terminate`. On success, the response will be empty with a status code of 200. This endpoint can be accessed via the [MooseControl](moosecontrol/index.md optional=true) python utility via `setTerminate()`.
147147

148148
!syntax parameters /Controls/WebServerControl
149149

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//* This file is part of the MOOSE framework
2+
//* https://mooseframework.inl.gov
3+
//*
4+
//* All rights reserved, see COPYRIGHT for full restrictions
5+
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6+
//*
7+
//* Licensed under LGPL 2.1, please see LICENSE for details
8+
//* https://www.gnu.org/licenses/lgpl-2.1.html
9+
10+
#pragma once
11+
12+
#include "Action.h"
13+
14+
/**
15+
* Starts the web server(s) for the WebServerControl objects.
16+
*/
17+
class StartWebServerControlAction : public Action
18+
{
19+
public:
20+
static InputParameters validParams();
21+
22+
StartWebServerControlAction(const InputParameters & parameters);
23+
24+
virtual void act() override final;
25+
};

framework/include/base/Factory.h

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,46 @@ class Factory
167167
const InputParameters * currentlyConstructing() const;
168168

169169
private:
170+
/**
171+
* Internal method for checking if the created smart pointer is of the correct expected type.
172+
*
173+
* Used in create<T> and createUnique<T>.
174+
*/
175+
template <class T, class SmartPtr>
176+
void createCheckObjectType(const SmartPtr & object, const std::string & obj_name) const;
177+
178+
/**
179+
* Internal method for creating a MooseObject, either as a
180+
* shared_ptr or as a unique_ptr.
181+
*
182+
* This is needed because we need to explicitly create objects
183+
* that are requested as a shared_ptr with make_shared, so that
184+
* the std::enable_shared_from_this interface will work for
185+
* those objects.
186+
*
187+
* We avoid code duplication by putting the creation logic
188+
* for shared_ptr and unique_ptr in the same method.
189+
*
190+
* This is explicitly instantiated for
191+
* std::unique_ptr<MooseObject> and std::shared_ptr<MooseObject>
192+
* in Factory.C.
193+
*
194+
* @param obj_name Type of the object being constructed
195+
* @param name Name for the object
196+
* @param parameters Parameters this object should have
197+
* @param tid The thread id that this copy will be created for
198+
* @param deprecated_method_name The name of the method to throw a deprecated warning for, if
199+
* any
200+
* @return The created MooseObject
201+
*/
202+
///@{
203+
template <class ptr_type>
204+
ptr_type createTempl(const std::string & obj_name,
205+
const std::string & name,
206+
const InputParameters & parameters,
207+
const THREAD_ID tid,
208+
const std::optional<std::string> & deprecated_method_name);
209+
170210
/**
171211
* Parse time string (mm/dd/yyyy HH:MM)
172212
* @param t_str String with the object expiration date, this must be in the form mm/dd/yyyy
@@ -244,6 +284,16 @@ class Factory
244284
std::map<const MooseObject *, unsigned int> _clone_counter;
245285
};
246286

287+
template <class T, class SmartPtr>
288+
void
289+
Factory::createCheckObjectType(const SmartPtr & object, const std::string & obj_name) const
290+
{
291+
if (!dynamic_cast<T *>(object.get()))
292+
mooseError("We expected to create an object of type '" + MooseUtils::prettyCppType<T>() +
293+
"'.\nInstead we received a parameters object for type '" + obj_name +
294+
"'.\nDid you call the wrong \"add\" method in your Action?");
295+
}
296+
247297
template <typename T>
248298
std::unique_ptr<T>
249299
Factory::createUnique(const std::string & obj_name,
@@ -252,11 +302,7 @@ Factory::createUnique(const std::string & obj_name,
252302
const THREAD_ID tid)
253303
{
254304
auto object = createUnique(obj_name, name, parameters, tid, false);
255-
if (!dynamic_cast<T *>(object.get()))
256-
mooseError("We expected to create an object of type '" + libMesh::demangle(typeid(T).name()) +
257-
"'.\nInstead we received a parameters object for type '" + obj_name +
258-
"'.\nDid you call the wrong \"add\" method in your Action?");
259-
305+
createCheckObjectType<T>(object, obj_name);
260306
return std::unique_ptr<T>(static_cast<T *>(object.release()));
261307
}
262308

@@ -267,7 +313,9 @@ Factory::create(const std::string & obj_name,
267313
const InputParameters & parameters,
268314
const THREAD_ID tid)
269315
{
270-
return std::move(createUnique<T>(obj_name, name, parameters, tid));
316+
auto object = create(obj_name, name, parameters, tid, false);
317+
createCheckObjectType<T>(object, obj_name);
318+
return std::static_pointer_cast<T>(object);
271319
}
272320

273321
template <typename T>

framework/include/base/Registry.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct RegistryEntryBase : public RegistryEntryData
126126
virtual ~RegistryEntryBase() {}
127127
/// proxy functions
128128
virtual std::unique_ptr<MooseObject> build(const InputParameters & parameters) = 0;
129+
virtual std::shared_ptr<MooseObject> buildShared(const InputParameters & parameters) = 0;
129130
virtual std::shared_ptr<Action> buildAction(const InputParameters & parameters) = 0;
130131
virtual InputParameters buildParameters() = 0;
131132
/// resolve the name from _classname, _alias, and _name
@@ -143,8 +144,9 @@ struct RegistryEntryBase : public RegistryEntryData
143144
template <typename T>
144145
struct RegistryEntry : public RegistryEntryBase
145146
{
146-
RegistryEntry(const RegistryEntryData & data) : RegistryEntryBase(data) {}
147+
RegistryEntry(const RegistryEntryData & data);
147148
virtual std::unique_ptr<MooseObject> build(const InputParameters & parameters) override;
149+
virtual std::shared_ptr<MooseObject> buildShared(const InputParameters & parameters) override;
148150
virtual std::shared_ptr<Action> buildAction(const InputParameters & parameters) override;
149151
virtual InputParameters buildParameters() override;
150152
};
@@ -281,7 +283,7 @@ class Registry
281283
FRIEND_TEST(RegistryTest, appNameFromAppPathFailed);
282284
///@}
283285

284-
Registry(){};
286+
Registry() {};
285287

286288
/**
287289
* Manually set the data file paths.
@@ -329,13 +331,28 @@ Registry::getRegisteredName()
329331
return getClassName<T>();
330332
}
331333

334+
template <typename T>
335+
RegistryEntry<T>::RegistryEntry(const RegistryEntryData & data) : RegistryEntryBase(data)
336+
{
337+
static_assert(std::is_base_of_v<MooseObject, T> || std::is_base_of_v<Action, T>,
338+
"Not derived from MooseObject or Action");
339+
}
340+
332341
template <typename T>
333342
std::unique_ptr<MooseObject>
334343
RegistryEntry<T>::build(const InputParameters & parameters)
335344
{
336345
if constexpr (std::is_base_of_v<MooseObject, T>)
337346
return std::make_unique<T>(parameters);
338-
mooseError("The object to be built is not derived from MooseObject.");
347+
mooseError(MooseUtils::prettyCppType<T>(), " to be built is not a MooseObject.");
348+
}
349+
template <typename T>
350+
std::shared_ptr<MooseObject>
351+
RegistryEntry<T>::buildShared(const InputParameters & parameters)
352+
{
353+
if constexpr (std::is_base_of_v<MooseObject, T>)
354+
return std::make_shared<T>(parameters);
355+
mooseError(MooseUtils::prettyCppType<T>(), " to be built is not a MooseObject.");
339356
}
340357

341358
template <typename T>

0 commit comments

Comments
 (0)