ClusterConfig
is a class for configuring Docker cluster operations. It allows you to set execution strategy, error detail level, configure retries, set node priorities, and other cluster parameters.
Sangezar\DockerClient\Config
public static function create(): self
Creates a new cluster configuration instance.
ClusterConfig
public function setExecutionStrategy(string $strategy): self
Sets the execution strategy for operations on cluster nodes.
$strategy
- Execution strategy:
AbstractOperations::EXECUTION_SEQUENTIAL
- sequential executionAbstractOperations::EXECUTION_PARALLEL
- parallel executionInvalidParameterValueException
- if an unknown strategy is specifiedpublic function setErrorDetailLevel(string $level): self
Sets the error detail level.
$level
- Detail level:
AbstractOperations::ERROR_LEVEL_BASIC
- basic level (only messages)AbstractOperations::ERROR_LEVEL_STANDARD
- standard level (messages, exception type, code)AbstractOperations::ERROR_LEVEL_DETAILED
- detailed level (all details, including stack trace)InvalidParameterValueException
- if an unknown level is specifiedpublic function setRetryConfig(bool $enable, ?int $maxRetries = null, ?int $retryDelay = null, ?bool $exponentialBackoff = null): self
Configures retry parameters for error handling.
$enable
- Enable retries$maxRetries
- Maximum number of retries (default 3)$retryDelay
- Initial delay between retries in milliseconds (default 1000)$exponentialBackoff
- Whether to use exponential delay increase between retriesInvalidParameterValueException
- if parameters are invalidpublic function setOperationTimeout(int $seconds): self
Sets the timeout for cluster node operations.
$seconds
- Timeout in secondsInvalidParameterValueException
- if the timeout value is invalidpublic function setNodePriority(string $nodeName, int $priority): self
Sets the priority for a node.
$nodeName
- Node name$priority
- Priority (1 is highest)InvalidParameterValueException
- if the priority value is invalidpublic function setDefaultNodeTag(?string $tag): self
Sets the default tag for operations.
$tag
- Tag for filtering nodespublic function addFailoverNode(string $nodeName): self
Adds a node to the list of failover nodes.
$nodeName
- Node name to use in case of main nodes failureInvalidParameterValueException
- if the node name is emptypublic function getExecutionStrategy(): string
Gets the current execution strategy.
public function getErrorDetailLevel(): string
Gets the current error detail level.
public function isRetryOnFailure(): bool
Checks if retries are allowed.
true
if retries are allowed, false
otherwisepublic function getMaxRetries(): int
Gets the maximum number of retries.
public function getRetryDelay(): int
Gets the delay between retries.
public function isExponentialBackoff(): bool
Checks if exponential delay increase is used.
true
if exponential increase is used, false
otherwisepublic function getOperationTimeout(): int
Gets the operation timeout.
public function getNodePriorities(): array
Gets node priorities.
public function getDefaultNodeTag(): ?string
Gets the default tag.
null
if not setpublic function getFailoverNodes(): array
Gets the list of failover nodes.
public function toArray(): array
Converts the configuration to an array.
use Sangezar\DockerClient\Config\ClusterConfig;
use Sangezar\DockerClient\Cluster\Operations\AbstractOperations;
// Creating configuration with default parameters
$config = ClusterConfig::create();
// Setting execution strategy and error level
$config->setExecutionStrategy(AbstractOperations::EXECUTION_PARALLEL)
->setErrorDetailLevel(AbstractOperations::ERROR_LEVEL_DETAILED);
use Sangezar\DockerClient\Config\ClusterConfig;
$config = ClusterConfig::create();
// Allow retries with maximum 5 attempts
// and 500ms delay between attempts
$config->setRetryConfig(true, 5, 500, true);
// Set operation timeout to 60 seconds
$config->setOperationTimeout(60);
use Sangezar\DockerClient\Config\ClusterConfig;
$config = ClusterConfig::create();
// Setting priorities for nodes
$config->setNodePriority('node1', 1) // highest priority
->setNodePriority('node2', 2)
->setNodePriority('node3', 3);
// Adding failover nodes
$config->addFailoverNode('backup-node1')
->addFailoverNode('backup-node2');
// Setting default tag
$config->setDefaultNodeTag('production');
use Sangezar\DockerClient\Config\ClusterConfig;
$config = ClusterConfig::create()
->setExecutionStrategy(AbstractOperations::EXECUTION_PARALLEL)
->setRetryConfig(true, 3, 1000, true);
// Checking if retries are allowed
if ($config->isRetryOnFailure()) {
echo "Retries are allowed\n";
echo "Maximum number of attempts: " . $config->getMaxRetries() . "\n";
echo "Delay: " . $config->getRetryDelay() . " ms\n";
}
// Getting all settings as an array
$allSettings = $config->toArray();