github.com/hernad/nomad@v1.6.112/ui/app/serializers/agent.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import ApplicationSerializer from './application'; 7 import AdapterError from '@ember-data/adapter/error'; 8 import classic from 'ember-classic-decorator'; 9 10 @classic 11 export default class AgentSerializer extends ApplicationSerializer { 12 attrs = { 13 datacenter: 'dc', 14 address: 'Addr', 15 serfPort: 'Port', 16 }; 17 18 normalize(typeHash, hash) { 19 if (!hash) { 20 // It's unusual to throw an adapter error from a serializer, 21 // but there is no single server end point so the serializer 22 // acts like the API in this case. 23 const error = new AdapterError([{ status: '404' }]); 24 25 error.message = 26 'Requested Agent was not found in set of available Agents'; 27 throw error; 28 } 29 30 hash.ID = hash.Name; 31 hash.Datacenter = hash.Tags && hash.Tags.dc; 32 hash.Region = hash.Tags && hash.Tags.region; 33 hash.RpcPort = hash.Tags && hash.Tags.port; 34 35 return super.normalize(typeHash, hash); 36 } 37 38 normalizeResponse(store, typeClass, hash, ...args) { 39 return super.normalizeResponse( 40 store, 41 typeClass, 42 hash.Members || [], 43 ...args 44 ); 45 } 46 47 normalizeSingleResponse(store, typeClass, hash, id, ...args) { 48 return super.normalizeSingleResponse( 49 store, 50 typeClass, 51 hash.findBy('Name', id), 52 id, 53 ...args 54 ); 55 } 56 }