kibana/x-pack/plugins/monitoring/server/cloud/cloud_response.js
Chris Roberson 3a396027f6
[Monitoring] Migrate server to NP (#56675)
* First pass

* First pass

* Add new routes

* Getting closer

* Remove legacy server code, and other fixes

* Register the plugin with xpack

* Pass a legacy client to telemetry

* Suport callWithInternalUser

* Remove this

* More NP work

* Fix some tests

* Fix broken test

* Move over new telemetry changes, and fix other issues

* Fix TODO item

* Reuse the same schema as elasticsearch module

* Use a singular config definition here

* Disable this for now

* Use the right method

* Use custom config again

* Tweak the config to make this optional

* Remove these

* Remove these unnecessary files

* Fix jest test

* Fix some linting issues

* Fix type issue

* Fix localization issues

* Use the elasticsearch config

* Remove todos

* Fix this check

* Move kibana alerting over

* PR feedback

* Use new metrics core service

* Change config for xpack_api_polling_frequency_millis

* Make sure this is disabled for now

* Disable both

* Update this to the new function

* Tighten up legacy api needs

* Check for existence

* Fix jest tests

* Cleaning up the plugin definition

* Create custom type in our plugin

* Revert this change

* Fix CI issues

* Add these tests back

* Just use a different collector type

* Handle errors better

* Use custom type

* PR feedback

* Fix type issues

* PR feedback
2020-03-20 14:02:15 -04:00

80 lines
2.5 KiB
JavaScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/**
* {@code CloudServiceResponse} represents a single response from any individual {@code CloudService}.
*/
export class CloudServiceResponse {
/**
* Create an unconfirmed {@code CloudServiceResponse} by the {@code name}.
*
* @param {String} name The name of the {@code CloudService}.
* @return {CloudServiceResponse} Never {@code null}.
*/
static unconfirmed(name) {
return new CloudServiceResponse(name, false, {});
}
/**
* Create a new {@code CloudServiceResponse}.
*
* @param {String} name The name of the {@code CloudService}.
* @param {Boolean} confirmed Confirmed to be the current {@code CloudService}.
* @param {String} id The optional ID of the VM (depends on the cloud service).
* @param {String} vmType The optional type of VM (depends on the cloud service).
* @param {String} region The optional region of the VM (depends on the cloud service).
* @param {String} availabilityZone The optional availability zone within the region (depends on the cloud service).
* @param {Object} metadata The optional metadata associated with the VM.
*/
constructor(name, confirmed, { id, vmType, region, zone, metadata }) {
this._name = name;
this._confirmed = confirmed;
this._id = id;
this._metadata = metadata;
this._region = region;
this._vmType = vmType;
this._zone = zone;
}
/**
* Get the name of the {@code CloudService} associated with the current response.
*
* @return {String} The cloud service that created this response.
*/
getName() {
return this._name;
}
/**
* Determine if the Cloud Service is confirmed to exist.
*
* @return {Boolean} {@code true} to indicate that Kibana is running in this cloud environment.
*/
isConfirmed() {
return this._confirmed;
}
/**
* Create a plain JSON object that can be indexed that represents the response.
*
* @return {Object} Never {@code null} object.
* @throws {Error} if this response is not {@code confirmed}.
*/
toJSON() {
if (!this._confirmed) {
throw new Error(`[${this._name}] is not confirmed`);
}
return {
name: this._name,
id: this._id,
vm_type: this._vmType,
region: this._region,
zone: this._zone,
metadata: this._metadata,
};
}
}