1: <?php
2:
3: namespace Saklient\Cloud\Resources;
4:
5: require_once __DIR__ . "/../../../Saklient/Cloud/Client.php";
6: use \Saklient\Cloud\Client;
7: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Resource.php";
8: use \Saklient\Cloud\Resources\Resource;
9: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Icon.php";
10: use \Saklient\Cloud\Resources\Icon;
11: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/FtpInfo.php";
12: use \Saklient\Cloud\Resources\FtpInfo;
13: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/DiskPlan.php";
14: use \Saklient\Cloud\Resources\DiskPlan;
15: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Server.php";
16: use \Saklient\Cloud\Resources\Server;
17: require_once __DIR__ . "/../../../Saklient/Cloud/Enums/EScope.php";
18: use \Saklient\Cloud\Enums\EScope;
19: require_once __DIR__ . "/../../../Saklient/Cloud/Enums/EAvailability.php";
20: use \Saklient\Cloud\Enums\EAvailability;
21: require_once __DIR__ . "/../../../Saklient/Errors/HttpException.php";
22: use \Saklient\Errors\HttpException;
23: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
24: use \Saklient\Errors\SaklientException;
25: require_once __DIR__ . "/../../../Saklient/Util.php";
26: use \Saklient\Util;
27:
28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
47: class Archive extends Resource {
48:
49: 50: 51: 52: 53: 54: 55:
56: protected $m_id;
57:
58: 59: 60: 61: 62: 63: 64:
65: protected $m_scope;
66:
67: 68: 69: 70: 71: 72: 73:
74: protected $m_name;
75:
76: 77: 78: 79: 80: 81: 82:
83: protected $m_description;
84:
85: 86: 87: 88: 89: 90: 91:
92: protected $m_tags;
93:
94: 95: 96: 97: 98: 99: 100:
101: protected $m_icon;
102:
103: 104: 105: 106: 107: 108: 109:
110: protected $m_displayOrder;
111:
112: 113: 114: 115: 116: 117: 118:
119: protected $m_sizeMib;
120:
121: 122: 123: 124: 125: 126: 127:
128: protected $m_serviceClass;
129:
130: 131: 132: 133: 134: 135: 136:
137: protected $m_plan;
138:
139: 140: 141: 142: 143: 144: 145:
146: protected $m_availability;
147:
148: 149: 150: 151: 152: 153:
154: protected function _apiPath()
155: {
156: return "/archive";
157: }
158:
159: 160: 161: 162: 163: 164:
165: protected function _rootKey()
166: {
167: return "Archive";
168: }
169:
170: 171: 172: 173: 174: 175:
176: protected function _rootKeyM()
177: {
178: return "Archives";
179: }
180:
181: 182: 183: 184: 185: 186:
187: public function _className()
188: {
189: return "Archive";
190: }
191:
192: 193: 194: 195: 196: 197:
198: public function _id()
199: {
200: return $this->get_id();
201: }
202:
203: 204: 205: 206: 207: 208:
209: public function save()
210: {
211: return $this->_save();
212: }
213:
214: 215: 216: 217: 218: 219:
220: public function reload()
221: {
222: return $this->_reload();
223: }
224:
225: 226: 227: 228: 229: 230: 231:
232: public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
233: {
234: parent::__construct($client);
235: Util::validateArgCount(func_num_args(), 2);
236: Util::validateType($client, "\\Saklient\\Cloud\\Client");
237: Util::validateType($wrapped, "boolean");
238: $this->apiDeserialize($obj, $wrapped);
239: }
240:
241: 242: 243: 244: 245:
246: protected function get_isAvailable()
247: {
248: return $this->get_availability() == EAvailability::available;
249: }
250:
251:
252:
253: 254: 255: 256: 257:
258: protected function get_sizeGib()
259: {
260: $sizeMib = $this->get_sizeMib();
261: return $sizeMib == null ? null : $sizeMib >> 10;
262: }
263:
264: 265: 266: 267: 268: 269:
270: protected function set_sizeGib($sizeGib)
271: {
272: Util::validateArgCount(func_num_args(), 1);
273: Util::validateType($sizeGib, "int");
274: $this->set_sizeMib($sizeGib == null ? null : $sizeGib * 1024);
275: return $sizeGib;
276: }
277:
278:
279:
280: 281: 282: 283: 284: 285:
286: private $_source;
287:
288: 289: 290: 291: 292:
293: public function get_source()
294: {
295: return $this->_source;
296: }
297:
298: 299: 300: 301: 302: 303:
304: public function set_source(\Saklient\Cloud\Resources\Resource $source=null)
305: {
306: Util::validateArgCount(func_num_args(), 1);
307: Util::validateType($source, "\\Saklient\\Cloud\\Resources\\Resource");
308: $this->_source = $source;
309: return $source;
310: }
311:
312:
313:
314: 315: 316: 317: 318: 319:
320: protected $_ftpInfo;
321:
322: 323: 324: 325: 326:
327: public function get_ftpInfo()
328: {
329: return $this->_ftpInfo;
330: }
331:
332:
333:
334: 335: 336: 337: 338: 339: 340: 341:
342: protected function _onAfterApiDeserialize($r, $root)
343: {
344: Util::validateArgCount(func_num_args(), 2);
345: if ($root != null) {
346: if (array_key_exists("FTPServer", (array)($root))) {
347: $ftp = $root->{"FTPServer"};
348: if ($ftp != null) {
349: $this->_ftpInfo = new FtpInfo($ftp);
350: }
351: }
352: }
353: if ($r != null) {
354: if (array_key_exists("SourceArchive", (array)($r))) {
355: $s = $r->{"SourceArchive"};
356: if ($s != null) {
357: $id = $s->{"ID"};
358: if ($id != null) {
359: $this->_source = new Archive($this->_client, $s);
360: }
361: }
362: }
363: if (array_key_exists("SourceDisk", (array)($r))) {
364: $s = $r->{"SourceDisk"};
365: if ($s != null) {
366: $id = $s->{"ID"};
367: if ($id != null) {
368: $this->_source = Resource::createWith("Disk", $this->_client, $s);
369: }
370: }
371: }
372: }
373: }
374:
375: 376: 377: 378: 379: 380: 381: 382:
383: protected function _onAfterApiSerialize($r, $withClean)
384: {
385: Util::validateArgCount(func_num_args(), 2);
386: Util::validateType($withClean, "boolean");
387: if ($r == null) {
388: return;
389: }
390: if ($this->_source != null) {
391: if ($this->_source->_className() == "Archive") {
392: $s = $withClean ? $this->_source->apiSerialize(true) : (object)['ID' => $this->_source->_id()];
393: $r->{"SourceArchive"} = $s;
394: }
395: else {
396: if ($this->_source->_className() == "Disk") {
397: $s = $withClean ? $this->_source->apiSerialize(true) : (object)['ID' => $this->_source->_id()];
398: $r->{"SourceDisk"} = $s;
399: }
400: else {
401: $this->_source = null;
402: Util::validateType($this->_source, "Disk or Archive", true);
403: }
404: }
405: }
406: }
407:
408: 409: 410: 411: 412: 413: 414: 415: 416:
417: public function openFtp($reset=false)
418: {
419: Util::validateType($reset, "boolean");
420: $path = $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/ftp";
421: $q = (object)[];
422: Util::setByPath($q, "ChangePassword", $reset);
423: $result = $this->_client->request("PUT", $path, $q);
424: $this->_onAfterApiDeserialize(null, $result);
425: return $this;
426: }
427:
428: 429: 430: 431: 432: 433:
434: public function closeFtp()
435: {
436: $path = $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/ftp";
437: $this->_client->request("DELETE", $path);
438: $this->_ftpInfo = null;
439: return $this;
440: }
441:
442: 443: 444: 445: 446: 447: 448:
449: public function sleepWhileCopying($timeoutSec=3600)
450: {
451: Util::validateType($timeoutSec, "int");
452: $step = 3;
453: while (0 < $timeoutSec) {
454: try {
455: $this->reload();
456: }
457: catch (HttpException $ex) {
458: }
459: $a = $this->get_availability();
460: if ($a == EAvailability::available) {
461: return true;
462: }
463: if ($a != EAvailability::migrating) {
464: $timeoutSec = 0;
465: }
466: $timeoutSec -= $step;
467: if (0 < $timeoutSec) {
468: Util::sleep($step);
469: }
470: }
471: return false;
472: }
473:
474: 475: 476: 477: 478:
479: private $n_id = false;
480:
481: 482: 483: 484: 485: 486: 487:
488: private function get_id()
489: {
490: return $this->m_id;
491: }
492:
493:
494:
495: 496: 497: 498: 499:
500: private $n_scope = false;
501:
502: 503: 504: 505: 506: 507: 508:
509: private function get_scope()
510: {
511: return $this->m_scope;
512: }
513:
514:
515:
516: 517: 518: 519: 520:
521: private $n_name = false;
522:
523: 524: 525: 526: 527: 528: 529:
530: private function get_name()
531: {
532: return $this->m_name;
533: }
534:
535: 536: 537: 538: 539: 540: 541: 542:
543: private function set_name($v)
544: {
545: Util::validateArgCount(func_num_args(), 1);
546: Util::validateType($v, "string");
547: $this->m_name = $v;
548: $this->n_name = true;
549: return $this->m_name;
550: }
551:
552:
553:
554: 555: 556: 557: 558:
559: private $n_description = false;
560:
561: 562: 563: 564: 565: 566: 567:
568: private function get_description()
569: {
570: return $this->m_description;
571: }
572:
573: 574: 575: 576: 577: 578: 579: 580:
581: private function set_description($v)
582: {
583: Util::validateArgCount(func_num_args(), 1);
584: Util::validateType($v, "string");
585: $this->m_description = $v;
586: $this->n_description = true;
587: return $this->m_description;
588: }
589:
590:
591:
592: 593: 594: 595: 596:
597: private $n_tags = false;
598:
599: 600: 601: 602: 603: 604: 605:
606: private function get_tags()
607: {
608: $this->n_tags = true;
609: return $this->m_tags;
610: }
611:
612: 613: 614: 615: 616: 617: 618: 619:
620: private function set_tags($v)
621: {
622: Util::validateArgCount(func_num_args(), 1);
623: Util::validateType($v, "\\ArrayObject");
624: if (is_array($v)) $v = Client::array2ArrayObject($v);
625: $this->m_tags = $v;
626: $this->n_tags = true;
627: return $this->m_tags;
628: }
629:
630:
631:
632: 633: 634: 635: 636:
637: private $n_icon = false;
638:
639: 640: 641: 642: 643: 644: 645:
646: private function get_icon()
647: {
648: return $this->m_icon;
649: }
650:
651: 652: 653: 654: 655: 656: 657: 658:
659: private function set_icon(\Saklient\Cloud\Resources\Icon $v=null)
660: {
661: Util::validateArgCount(func_num_args(), 1);
662: Util::validateType($v, "\\Saklient\\Cloud\\Resources\\Icon");
663: $this->m_icon = $v;
664: $this->n_icon = true;
665: return $this->m_icon;
666: }
667:
668:
669:
670: 671: 672: 673: 674:
675: private $n_displayOrder = false;
676:
677: 678: 679: 680: 681: 682: 683:
684: private function get_displayOrder()
685: {
686: return $this->m_displayOrder;
687: }
688:
689: 690: 691: 692: 693: 694: 695: 696:
697: private function set_displayOrder($v)
698: {
699: Util::validateArgCount(func_num_args(), 1);
700: Util::validateType($v, "int");
701: $this->m_displayOrder = $v;
702: $this->n_displayOrder = true;
703: return $this->m_displayOrder;
704: }
705:
706:
707:
708: 709: 710: 711: 712:
713: private $n_sizeMib = false;
714:
715: 716: 717: 718: 719: 720: 721:
722: private function get_sizeMib()
723: {
724: return $this->m_sizeMib;
725: }
726:
727: 728: 729: 730: 731: 732: 733: 734:
735: private function set_sizeMib($v)
736: {
737: Util::validateArgCount(func_num_args(), 1);
738: Util::validateType($v, "int");
739: if (!$this->isNew) {
740: throw new SaklientException("immutable_field", "Immutable fields cannot be modified after the resource creation: " . "Saklient\\Cloud\\Resources\\Archive#sizeMib");
741: }
742: $this->m_sizeMib = $v;
743: $this->n_sizeMib = true;
744: return $this->m_sizeMib;
745: }
746:
747:
748:
749: 750: 751: 752: 753:
754: private $n_serviceClass = false;
755:
756: 757: 758: 759: 760: 761: 762:
763: private function get_serviceClass()
764: {
765: return $this->m_serviceClass;
766: }
767:
768:
769:
770: 771: 772: 773: 774:
775: private $n_plan = false;
776:
777: 778: 779: 780: 781: 782: 783:
784: private function get_plan()
785: {
786: return $this->m_plan;
787: }
788:
789:
790:
791: 792: 793: 794: 795:
796: private $n_availability = false;
797:
798: 799: 800: 801: 802: 803: 804:
805: private function get_availability()
806: {
807: return $this->m_availability;
808: }
809:
810:
811:
812: 813: 814: 815: 816: 817: 818:
819: protected function apiDeserializeImpl($r)
820: {
821: Util::validateArgCount(func_num_args(), 1);
822: $this->isNew = $r == null;
823: if ($this->isNew) {
824: $r = (object)[];
825: }
826: $this->isIncomplete = false;
827: if (Util::existsPath($r, "ID")) {
828: $this->m_id = Util::getByPath($r, "ID") == null ? null : "" . Util::getByPath($r, "ID");
829: }
830: else {
831: $this->m_id = null;
832: $this->isIncomplete = true;
833: }
834: $this->n_id = false;
835: if (Util::existsPath($r, "Scope")) {
836: $this->m_scope = Util::getByPath($r, "Scope") == null ? null : "" . Util::getByPath($r, "Scope");
837: }
838: else {
839: $this->m_scope = null;
840: $this->isIncomplete = true;
841: }
842: $this->n_scope = false;
843: if (Util::existsPath($r, "Name")) {
844: $this->m_name = Util::getByPath($r, "Name") == null ? null : "" . Util::getByPath($r, "Name");
845: }
846: else {
847: $this->m_name = null;
848: $this->isIncomplete = true;
849: }
850: $this->n_name = false;
851: if (Util::existsPath($r, "Description")) {
852: $this->m_description = Util::getByPath($r, "Description") == null ? null : "" . Util::getByPath($r, "Description");
853: }
854: else {
855: $this->m_description = null;
856: $this->isIncomplete = true;
857: }
858: $this->n_description = false;
859: if (Util::existsPath($r, "Tags")) {
860: if (Util::getByPath($r, "Tags") == null) {
861: $this->m_tags = new \ArrayObject([]);
862: }
863: else {
864: $this->m_tags = new \ArrayObject([]);
865: foreach (Util::getByPath($r, "Tags") as $t) {
866: $v1 = null;
867: $v1 = $t == null ? null : "" . $t;
868: $this->m_tags->append($v1);
869: }
870: }
871: }
872: else {
873: $this->m_tags = null;
874: $this->isIncomplete = true;
875: }
876: $this->n_tags = false;
877: if (Util::existsPath($r, "Icon")) {
878: $this->m_icon = Util::getByPath($r, "Icon") == null ? null : new Icon($this->_client, Util::getByPath($r, "Icon"));
879: }
880: else {
881: $this->m_icon = null;
882: $this->isIncomplete = true;
883: }
884: $this->n_icon = false;
885: if (Util::existsPath($r, "DisplayOrder")) {
886: $this->m_displayOrder = Util::getByPath($r, "DisplayOrder") == null ? null : intval("" . Util::getByPath($r, "DisplayOrder"));
887: }
888: else {
889: $this->m_displayOrder = null;
890: $this->isIncomplete = true;
891: }
892: $this->n_displayOrder = false;
893: if (Util::existsPath($r, "SizeMB")) {
894: $this->m_sizeMib = Util::getByPath($r, "SizeMB") == null ? null : intval("" . Util::getByPath($r, "SizeMB"));
895: }
896: else {
897: $this->m_sizeMib = null;
898: $this->isIncomplete = true;
899: }
900: $this->n_sizeMib = false;
901: if (Util::existsPath($r, "ServiceClass")) {
902: $this->m_serviceClass = Util::getByPath($r, "ServiceClass") == null ? null : "" . Util::getByPath($r, "ServiceClass");
903: }
904: else {
905: $this->m_serviceClass = null;
906: $this->isIncomplete = true;
907: }
908: $this->n_serviceClass = false;
909: if (Util::existsPath($r, "Plan")) {
910: $this->m_plan = Util::getByPath($r, "Plan") == null ? null : new DiskPlan($this->_client, Util::getByPath($r, "Plan"));
911: }
912: else {
913: $this->m_plan = null;
914: $this->isIncomplete = true;
915: }
916: $this->n_plan = false;
917: if (Util::existsPath($r, "Availability")) {
918: $this->m_availability = Util::getByPath($r, "Availability") == null ? null : "" . Util::getByPath($r, "Availability");
919: }
920: else {
921: $this->m_availability = null;
922: $this->isIncomplete = true;
923: }
924: $this->n_availability = false;
925: }
926:
927: 928: 929: 930: 931: 932:
933: protected function apiSerializeImpl($withClean=false)
934: {
935: Util::validateType($withClean, "boolean");
936: $missing = new \ArrayObject([]);
937: $ret = (object)[];
938: if ($withClean || $this->n_id) {
939: Util::setByPath($ret, "ID", $this->m_id);
940: }
941: if ($withClean || $this->n_scope) {
942: Util::setByPath($ret, "Scope", $this->m_scope);
943: }
944: if ($withClean || $this->n_name) {
945: Util::setByPath($ret, "Name", $this->m_name);
946: }
947: else {
948: if ($this->isNew) {
949: $missing->append("name");
950: }
951: }
952: if ($withClean || $this->n_description) {
953: Util::setByPath($ret, "Description", $this->m_description);
954: }
955: if ($withClean || $this->n_tags) {
956: Util::setByPath($ret, "Tags", new \ArrayObject([]));
957: foreach ($this->m_tags as $r1) {
958: $v = null;
959: $v = $r1;
960: $ret->{"Tags"}->append($v);
961: }
962: }
963: if ($withClean || $this->n_icon) {
964: Util::setByPath($ret, "Icon", $withClean ? ($this->m_icon == null ? null : $this->m_icon->apiSerialize($withClean)) : ($this->m_icon == null ? (object)['ID' => "0"] : $this->m_icon->apiSerializeID()));
965: }
966: if ($withClean || $this->n_displayOrder) {
967: Util::setByPath($ret, "DisplayOrder", $this->m_displayOrder);
968: }
969: if ($withClean || $this->n_sizeMib) {
970: Util::setByPath($ret, "SizeMB", $this->m_sizeMib);
971: }
972: if ($withClean || $this->n_serviceClass) {
973: Util::setByPath($ret, "ServiceClass", $this->m_serviceClass);
974: }
975: if ($withClean || $this->n_plan) {
976: Util::setByPath($ret, "Plan", $withClean ? ($this->m_plan == null ? null : $this->m_plan->apiSerialize($withClean)) : ($this->m_plan == null ? (object)['ID' => "0"] : $this->m_plan->apiSerializeID()));
977: }
978: if ($withClean || $this->n_availability) {
979: Util::setByPath($ret, "Availability", $this->m_availability);
980: }
981: if ($missing->count() > 0) {
982: throw new SaklientException("required_field", "Required fields must be set before the Archive creation: " . implode(", ", (array)($missing)));
983: }
984: return $ret;
985: }
986:
987: 988: 989:
990: public function __get($key) {
991: switch ($key) {
992: case "isAvailable": return $this->get_isAvailable();
993: case "sizeGib": return $this->get_sizeGib();
994: case "source": return $this->get_source();
995: case "ftpInfo": return $this->get_ftpInfo();
996: case "id": return $this->get_id();
997: case "scope": return $this->get_scope();
998: case "name": return $this->get_name();
999: case "description": return $this->get_description();
1000: case "tags": return $this->get_tags();
1001: case "icon": return $this->get_icon();
1002: case "displayOrder": return $this->get_displayOrder();
1003: case "sizeMib": return $this->get_sizeMib();
1004: case "serviceClass": return $this->get_serviceClass();
1005: case "plan": return $this->get_plan();
1006: case "availability": return $this->get_availability();
1007: default: return parent::__get($key);
1008: }
1009: }
1010:
1011: 1012: 1013:
1014: public function __set($key, $v) {
1015: switch ($key) {
1016: case "sizeGib": return $this->set_sizeGib($v);
1017: case "source": return $this->set_source($v);
1018: case "name": return $this->set_name($v);
1019: case "description": return $this->set_description($v);
1020: case "tags": return $this->set_tags($v);
1021: case "icon": return $this->set_icon($v);
1022: case "displayOrder": return $this->set_displayOrder($v);
1023: case "sizeMib": return $this->set_sizeMib($v);
1024: default: return parent::__set($key, $v);
1025: }
1026: }
1027:
1028: }
1029:
1030: