2023-10-02 11:38:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\Shared;
|
|
|
|
|
|
|
|
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;
|
2023-11-27 10:54:55 +00:00
|
|
|
public $container = [];
|
|
|
|
public $containers;
|
2023-10-02 11:38:16 +00:00
|
|
|
public $parameters;
|
|
|
|
public $query;
|
|
|
|
public $status;
|
2023-12-01 09:34:30 +00:00
|
|
|
public $serviceSubType;
|
2023-10-02 11:38:16 +00:00
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-11-27 10:54:55 +00:00
|
|
|
$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;
|
2023-11-08 14:40:06 +00:00
|
|
|
$containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id, 0);
|
2023-10-02 11:38:16 +00:00
|
|
|
if ($containers->count() > 0) {
|
2023-11-27 10:54:55 +00:00
|
|
|
$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;
|
|
|
|
} else if (data_get($this->parameters, 'service_uuid')) {
|
|
|
|
$this->type = 'service';
|
|
|
|
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
|
2023-12-01 09:34:30 +00:00
|
|
|
$service_name = data_get($this->parameters, 'service_name');
|
|
|
|
$this->serviceSubType = $this->resource->applications()->where('name', $service_name)->first();
|
|
|
|
if (!$this->serviceSubType) {
|
|
|
|
$this->serviceSubType = $this->resource->databases()->where('name', $service_name)->first();
|
|
|
|
}
|
2023-10-02 11:38:16 +00:00
|
|
|
$this->status = $this->resource->status;
|
|
|
|
$this->server = $this->resource->server;
|
|
|
|
$this->container = data_get($this->parameters, 'service_name') . '-' . $this->resource->uuid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.project.shared.logs');
|
|
|
|
}
|
|
|
|
}
|