Ejemplo n.º 1
0
 /**
  * Returns an instance of the database object for the requested node ID.
  *
  * @param  int $id
  * @return \Illuminate\Database\Eloquent\Model
  */
 public static function getByID($id)
 {
     // The Node is already cached.
     if (array_key_exists($id, self::$nodes)) {
         return self::$nodes[$id];
     }
     self::$nodes[$id] = Node::where('id', $id)->first();
     return self::$nodes[$id];
 }
Ejemplo n.º 2
0
 /**
  * List Specific Node
  *
  * Lists specific fields about a server or all fields pertaining to that node.
  *
  * @Get("/nodes/{id}/{?fields}")
  * @Versions({"v1"})
  * @Parameters({
  *      @Parameter("id", type="integer", required=true, description="The ID of the node to get information on."),
  *      @Parameter("fields", type="string", required=false, description="A comma delimidated list of fields to include.")
  * })
  * @Response(200)
  */
 public function view(Request $request, $id, $fields = null)
 {
     $query = Models\Node::where('id', $id);
     if (!is_null($request->input('fields'))) {
         foreach (explode(',', $request->input('fields')) as $field) {
             if (!empty($field)) {
                 $query->addSelect($field);
             }
         }
     }
     try {
         if (!$query->first()) {
             throw new NotFoundHttpException('No node by that ID was found.');
         }
         return ['node' => $query->first(), 'allocations' => ['assigned' => Models\Allocation::where('node', $id)->whereNotNull('assigned_to')->get(), 'unassigned' => Models\Allocation::where('node', $id)->whereNull('assigned_to')->get()]];
     } catch (NotFoundHttpException $ex) {
         throw $ex;
     } catch (\Exception $ex) {
         throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
     }
 }