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