Exemplo n.º 1
0
 /**
  * Returns a blueprint for an instance
  *
  * @param string $instanceId The instance to map
  * @param array  $options    Options ['user'=['email','password','remember_me'], 'commit' =>true|false,]
  *
  * @return array
  */
 public function make($instanceId, $options = [])
 {
     $_instance = $this->findInstance($instanceId);
     $_client = InstanceApiClient::connect($_instance);
     //        $_payload = [
     //            'email'       => array_get($options, 'email'),
     //            'password'    => array_get($options, 'password'),
     //            'remember_me' => array_get($options, 'remember_me', false),
     //        ];
     $_blueprint = ['instance' => $_instance->toArray(), 'resources' => [], 'database' => []];
     //  Get services
     $_result = $_client->resources();
     foreach ($_result as $_resource) {
         $_blueprint['resources'][$_resource->name] = [];
         try {
             $_response = $_client->get($_resource->name);
             $_blueprint['resources'][$_resource->name] = isset($_response->resource) ? $_response->resource : $_response;
         } catch (\Exception $_ex) {
         }
     }
     //  Get database
     $_blueprint['database'] = $this->getStoredData($_instance);
     //  Do not commit this blueprint
     if (array_get($options, 'commit', true)) {
         return $this->commitBlueprint($instanceId, $_blueprint);
     }
     return $_blueprint;
 }
Exemplo n.º 2
0
 /**
  * @return array
  */
 protected function gatherInstanceStatistics()
 {
     $_stats = [];
     $_lastGuestLocation = null;
     /** @type Instance $_instance */
     foreach (Instance::all() as $_instance) {
         $_stats[$_instance->instance_id_text] = ['uri' => $_instance->getProvisionedEndpoint()];
         $_api = InstanceApiClient::connect($_instance);
         try {
             if (!empty($_resources = $_api->resources())) {
                 $_list = [];
                 foreach ($_resources as $_resource) {
                     if (property_exists($_resource, 'name')) {
                         try {
                             if (false !== ($_result = $_api->resource($_resource->name))) {
                                 $_list[$_resource->name] = count($_result);
                             }
                         } catch (\Exception $_ex) {
                             $_list[$_resource->name] = 'unavailable';
                         }
                     }
                 }
                 $_stats[$_instance->instance_id_text]['resources'] = $_list;
                 $_stats[$_instance->instance_id_text]['_status'] = ['operational'];
             }
         } catch (\Exception $_ex) {
             //  Instance unavailable or not initialized
             $_stats[$_instance->instance_id_text]['resources'] = [];
             $_stats[$_instance->instance_id_text]['_status'] = ['unreachable'];
         }
     }
     return $_stats;
     //  The new way
     //return $this->telemetry->make('instance')->getTelemetry();
 }