lasthourcloud/app/Livewire/Project/Shared/Logs.php

91 lines
3.8 KiB
PHP
Raw Normal View History

2023-10-02 11:38:16 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Shared;
2023-10-02 11:38:16 +00:00
use App\Models\Application;
use App\Models\Server;
use App\Models\Service;
2023-10-24 12:31:28 +00:00
use App\Models\StandaloneMariadb;
2023-10-19 11:32:03 +00:00
use App\Models\StandaloneMongodb;
2023-10-24 12:31:28 +00:00
use App\Models\StandaloneMysql;
2023-10-02 11:38:16 +00:00
use App\Models\StandalonePostgresql;
2023-10-12 15:18:33 +00:00
use App\Models\StandaloneRedis;
2023-10-02 11:38:16 +00:00
use Livewire\Component;
class Logs extends Component
{
public ?string $type = null;
2023-10-24 12:31:28 +00:00
public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb $resource;
2023-10-02 11:38:16 +00:00
public Server $server;
public $container = [];
public $containers;
2023-10-02 11:38:16 +00:00
public $parameters;
public $query;
public $status;
public $serviceSubType;
2023-10-02 11:38:16 +00:00
public function mount()
{
$this->containers = collect();
2023-10-02 11:38:16 +00:00
$this->parameters = get_route_parameters();
$this->query = request()->query();
if (data_get($this->parameters, 'application_uuid')) {
$this->type = 'application';
$this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail();
$this->status = $this->resource->status;
$this->server = $this->resource->destination->server;
$containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id, 0);
2023-10-02 11:38:16 +00:00
if ($containers->count() > 0) {
$containers->each(function ($container) {
$this->containers->push(str_replace('/', '', $container['Names']));
});
2023-10-02 11:38:16 +00:00
}
} else if (data_get($this->parameters, 'database_uuid')) {
$this->type = 'database';
2023-10-12 15:18:33 +00:00
$resource = StandalonePostgresql::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
$resource = StandaloneRedis::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
2023-10-19 11:32:03 +00:00
$resource = StandaloneMongodb::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
2023-10-24 12:31:28 +00:00
$resource = StandaloneMysql::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
$resource = StandaloneMariadb::where('uuid', $this->parameters['database_uuid'])->first();
if (is_null($resource)) {
abort(404);
}
}
2023-10-19 11:32:03 +00:00
}
2023-10-12 15:18:33 +00:00
}
}
$this->resource = $resource;
2023-10-02 11:38:16 +00:00
$this->status = $this->resource->status;
$this->server = $this->resource->destination->server;
$this->container = $this->resource->uuid;
if (str(data_get($this,'resource.status'))->startsWith('running')) {
$this->containers->push($this->container);
}
2023-10-02 11:38:16 +00:00
} else if (data_get($this->parameters, 'service_uuid')) {
$this->type = 'service';
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
$this->resource->applications()->get()->each(function ($application) {
if (str(data_get($application, 'status'))->contains('running')) {
$this->containers->push(data_get($application, 'name') . '-' . data_get($this->resource, 'uuid'));
}
});
$this->resource->databases()->get()->each(function ($database) {
if (str(data_get($database, 'status'))->contains('running')) {
$this->containers->push(data_get($database, 'name') . '-' . data_get($this->resource, 'uuid'));
}
});
2023-10-02 11:38:16 +00:00
$this->server = $this->resource->server;
}
}
public function render()
{
return view('livewire.project.shared.logs');
}
}