addon = $addon; $this->product = $product; $this->push = new PusherNotification; $this->telegram = new Telegram; $this->order = $order; } /** * Execute the job. * * @return void */ public function handle(ServiceVCenter $serviceVCenter) { $product = ModuleVmware::with([ 'IpAddress.Host.Datacenter.vCenter' ])->find($this->product); $serviceVCenter->token = $product->IpAddress->Host->Datacenter->vCenter->token; $serviceVCenter->apiUri = $product->IpAddress->Host->Datacenter->vCenter->host; $VirtualMachine = $serviceVCenter->CheckVirtualMachine($product->vmware_id); if ($VirtualMachine === "Login_Again") { $token = $serviceVCenter->loginServer($product->IpAddress->Host->Datacenter->vCenter); if ($token) { $product->IpAddress->Host->Datacenter->vCenter->update(['token' => $token]); $serviceVCenter->token = $token; } $VirtualMachine = $serviceVCenter->CheckVirtualMachine($product->vmware_id); } if ($VirtualMachine['data']['operations_ready'] === true) { $StatusVirtualMachine = $serviceVCenter->PowerOffVirtualMachine($product->vmware_id); if ($StatusVirtualMachine['error']) { throw new \Exception(json_encode($StatusVirtualMachine['data'])); } $VirtualMachine = $serviceVCenter->CheckVirtualMachine($product->vmware_id); if ($VirtualMachine['error'] === true) { throw new \Exception(json_encode($VirtualMachine['message'])); } if ($VirtualMachine['data']['operations_ready']) { do { sleep(10); $VirtualMachine = $serviceVCenter->CheckVirtualMachine($product->vmware_id); } while ($VirtualMachine['data']['operations_ready'] === false); } } $DetailVirtualMachine = $serviceVCenter->GetDetailVirtualMachine($product->vmware_id); if ($DetailVirtualMachine['error']) { throw new \Exception(json_encode($DetailVirtualMachine['message'])); } $ResourceConfig = []; foreach ($this->addon as $key => $item) { switch ($key) { case "cpu": $ResourceConfig[$key] = $item + $DetailVirtualMachine['data']['cpu']['count']; break; case "ram": $ResourceConfig[$key] = $item + ($DetailVirtualMachine['data']['memory']['size_MiB']/1024); break; case "ssd": $ResourceConfig[$key] = $item + ($DetailVirtualMachine['data']['disks'][0]['value']['capacity']/1073741824); break; } } $jobs = []; foreach ($ResourceConfig as $key => $item) { switch (strtolower($key)) { case "cpu": UpgradeCPU::dispatchSync($product->id,$item); break; case "ram": UpgradeMemory::dispatchSync($product->id,$item); break; case "ssd": UpgradeDisk::dispatchSync($product->id,$item); break; } } $VirtualMachine = $serviceVCenter->CheckVirtualMachine($product->vmware_id); if ($VirtualMachine['data']['operations_ready'] === false) { VMJobs::dispatchSync($product->id,"Start"); } $order = $this->order; $SumAddon = InvoiceItem::whereHas("OrderItem",function ($query) use ($order) { $query->where('id',$order); })->sum('amount'); $product->increment('first_payment',$SumAddon); $product->increment('next_payment',$SumAddon); Event(new NotificationStatus("Nâng cấp cấu hình thành công",true)); } public function failed(Throwable $exception) { Event(new NotificationStatus("Notification: $exception->getMessages()",false)); $this->telegram->SendErrorMessage($exception->getMessage()); } }