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;
|
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-12-20 13:11:50 +00:00
|
|
|
if ($this->server->isSwarm()) {
|
|
|
|
$containers = collect([
|
|
|
|
[
|
|
|
|
'Names' => $this->resource->uuid . '_' . $this->resource->uuid,
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$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;
|
2023-12-20 13:11:50 +00:00
|
|
|
if (str(data_get($this, 'resource.status'))->startsWith('running')) {
|
2023-12-11 10:27:41 +00:00
|
|
|
$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();
|
2023-12-11 10:27:41 +00:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
}
|