2017-09-19 14:47:10 +00:00
|
|
|
import ApplicationSerializer from './application';
|
2019-10-15 18:32:58 +00:00
|
|
|
import AdapterError from '@ember-data/adapter/error';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
export default class AgentSerializer extends ApplicationSerializer {
|
|
|
|
attrs = {
|
2017-09-19 14:47:10 +00:00
|
|
|
datacenter: 'dc',
|
|
|
|
address: 'Addr',
|
|
|
|
serfPort: 'Port',
|
2020-06-11 21:23:00 +00:00
|
|
|
};
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
normalize(typeHash, hash) {
|
2017-09-28 17:47:02 +00:00
|
|
|
if (!hash) {
|
|
|
|
// It's unusual to throw an adapter error from a serializer,
|
|
|
|
// but there is no single server end point so the serializer
|
|
|
|
// acts like the API in this case.
|
|
|
|
const error = new AdapterError([{ status: '404' }]);
|
|
|
|
|
|
|
|
error.message = 'Requested Agent was not found in set of available Agents';
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
hash.ID = hash.Name;
|
|
|
|
hash.Datacenter = hash.Tags && hash.Tags.dc;
|
|
|
|
hash.Region = hash.Tags && hash.Tags.region;
|
|
|
|
hash.RpcPort = hash.Tags && hash.Tags.port;
|
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
return super.normalize(typeHash, hash);
|
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
normalizeResponse(store, typeClass, hash, ...args) {
|
2020-06-11 21:23:00 +00:00
|
|
|
return super.normalizeResponse(store, typeClass, hash.Members || [], ...args);
|
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
normalizeSingleResponse(store, typeClass, hash, id, ...args) {
|
2020-06-11 21:23:00 +00:00
|
|
|
return super.normalizeSingleResponse(store, typeClass, hash.findBy('Name', id), id, ...args);
|
|
|
|
}
|
|
|
|
}
|