Skip to content
Draft
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
7 changes: 6 additions & 1 deletion legacy/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"doctrine/cache": "~1.5",
"guzzlehttp/guzzle": "^7",
"platformsh/console-form": "^1@beta",
"platformsh/client": "^3@beta",
"platformsh/client": "dev-add-task-deployment-model as 3.0.0-beta5",
"symfony/console": "^7",
"symfony/yaml": "^7",
"symfony/finder": "^7",
Expand All @@ -31,6 +31,11 @@
{
"type": "vcs",
"url": "https://github.com/pjcdawkins/humbug_get_contents"
},
{
"type": "vcs",
"url": "https://github.com/platformsh/platformsh-client-php.git",
"no-api": true
}
],
"suggest": {
Expand Down
36 changes: 21 additions & 15 deletions legacy/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions legacy/src/Command/Resources/ResourcesGetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
use Platformsh\Cli\Service\PropertyFormatter;
use Platformsh\Cli\Service\Table;
use Platformsh\Client\Exception\EnvironmentStateException;
use Platformsh\Client\Model\Deployment\Task;
use Platformsh\Client\Model\Deployment\WebApp;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'resources:get', description: 'View the resources of apps and services on an environment', aliases: ['resources', 'res'])]
#[AsCommand(name: 'resources:get', description: 'View the resources of apps, tasks and services on an environment', aliases: ['resources', 'res'])]
class ResourcesGetCommand extends ResourcesCommandBase
{
/** @var array<string, string> */
Expand Down Expand Up @@ -51,6 +52,7 @@ protected function configure(): void
->addOption('service', 's', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by service name. This can select any service, including apps and workers.')
->addOption('app', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by app name')
->addOption('worker', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by worker name')
->addOption('task', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by task name')
->addOption('type', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by service, app or worker type, e.g. "postgresql"')
->addOption('cpu-type', null, InputOption::VALUE_OPTIONAL, 'Filter by CPU type, e.g "guaranteed"');
$this->selector->addProjectOption($this->getDefinition());
Expand Down Expand Up @@ -118,14 +120,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$hasObjectStorage = false;
foreach ($services as $name => $service) {
$properties = $service->getProperties();
// Tasks may not specify a profile yet; default so CPU/memory still resolve.
$containerProfile = $properties['container_profile'] ?? ($service instanceof Task ? 'BALANCED' : null);
if (!$this->table->formatIsMachineReadable() && !empty($autoscalingEnabled[$name])) {
$name .= ' ' . $autoscalingIndicator;
$hasAutoscalingIndicator = true;
}
$row = [
'service' => $name,
'type' => $this->propertyFormatter->format($service->type, 'service_type'),
'profile' => $properties['container_profile'] ?: $empty,
// The deployment exposes task sizing only (no service type).
'type' => $service instanceof Task ? $empty : $this->propertyFormatter->format($service->type, 'service_type'),
'profile' => $containerProfile ?: $empty,
'profile_size' => $empty,
'base_memory' => $empty,
'memory_ratio' => $empty,
Expand All @@ -137,8 +142,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'memory' => $empty,
];

if (isset($properties['container_profile']) && isset($containerProfiles[$properties['container_profile']][$properties['resources']['profile_size']])) {
$profileInfo = $containerProfiles[$properties['container_profile']][$properties['resources']['profile_size']];
if ($containerProfile !== null && isset($containerProfiles[$containerProfile][$properties['resources']['profile_size']])) {
$profileInfo = $containerProfiles[$containerProfile][$properties['resources']['profile_size']];
if ($cpuTypeOption != "" && isset($profileInfo['cpu_type']) && $profileInfo['cpu_type'] != $cpuTypeOption) {
continue;
}
Expand Down Expand Up @@ -176,7 +181,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$row['instance_count'] = isset($properties['instance_count']) ? $this->propertyFormatter->format($properties['instance_count'], 'instance_count') : '1';
// Tasks are run-to-completion containers and have no instance count.
if ($service instanceof Task) {
$row['instance_count'] = $notApplicable;
} else {
$row['instance_count'] = isset($properties['instance_count']) ? $this->propertyFormatter->format($properties['instance_count'], 'instance_count') : '1';
}

$rows[] = $row;
}
Expand Down
Loading
Loading